Can't change variables so how do I work around it.

J

Jason Lehman

I want to depending on a parameter in the XML change wether the div should
display or not. Do I have to repeat the whole block in two if containers
with the style display:none and one with display:block but then whenever I
have to make a change to the block I have to update in two places? Any help
would be appreciated.

My example:

<xsl:if test="RequirementGroup/@ReqMet = &quot;Y&quot;">

<div style="display:none;margin-left:1em;" id="Area_Info{$intArea_Info}">

<xsl:if test="string-length(Code) &gt; 0">

<br />Code:<xsl:for-each select="Code">

<xsl:apply-templates />

</xsl:for-each>

</xsl:if>

<br />

<span style="background-color:#336633; color:#FFFFFF; width:100%;
">Requirement Group:</span>

<xsl:apply-templates select="RequirementGroup" />

<br />Course Group:<xsl:apply-templates select="CourseGroup" />

<xsl:if test="string-length(Review) &gt; 0">

<br />Review: <xsl:apply-templates select="Review" />

</xsl:if>

<br />Summary: <xsl:apply-templates select="Summary" />

<br />

</div>

</xsl:if>

<xsl:if test="RequirementGroup/@ReqMet = &quot;N&quot;">

<div style="display:block;margin-left:1em;" id="Area_Info{$intArea_Info}">

<xsl:if test="string-length(Code) &gt; 0">

<br />Code:<xsl:for-each select="Code">

<xsl:apply-templates />

</xsl:for-each>

</xsl:if>

<br />

<span style="background-color:#336633; color:#FFFFFF; width:100%;
">Requirement Group:</span>

<xsl:apply-templates select="RequirementGroup" />

<br />Course Group:<xsl:apply-templates select="CourseGroup" />

<xsl:if test="string-length(Review) &gt; 0">

<br />Review: <xsl:apply-templates select="Review" />

</xsl:if>

<br />Summary: <xsl:apply-templates select="Summary" />

<br />

</div>

</xsl:if>
 
D

David Carlisle

Your question isn't very clear, however the answer to

I want to depending on a parameter in the XML change wether the div should
display or not. Do I have to repeat the whole block in two if containers
with the style display:none and one with display:block but then whenever I
have to make a change to the block I have to update in two places?

Is probably no.

If you only want to make the attriibute depend on the parameter just
place the conditional at that point.

<div id="Area_Info{$intArea_Info}">
<xsl:attribute name="style">
<xsl:text>display:</xsl:text>
<xsl:choose>
<xsl:when test="something">none</xsl:when>
<xsl:eek:therwise>block</xsl:eek:therwise>
</xsl:choose>
<xsl:text>;margin-left:1em;</xsl:text>
</xsl:attribute>
....



<xsl:if test="string-length(Code) &gt; 0">
incidentally, probably better to do
<xsl:if test="string(Code)">
(which is equivalent)
or
<xsl:if test="Code">
which isn't equivalent (it's true even if the first code is empty, unlike the first two)


David
 
J

Jason Lehman

I tried your example but it is not working for me. My test that I have in
my original example doesn't work in your example even though it is in the
same template block.

My Code:
<xsl:template match="Area">

<xsl:if test="RequirementGroup/@ReqMet = &quot;Y&quot;">

<span style="color:#FFCC00; font-size:15px; " id="Requirement_Met">

<div id="Area_Info_plus{$intArea_Info}"
style="width=1em;display:inline;">+</div><div
id="Area_Info_minus{$intArea_Info}" style="width=1em;display:none;">-</div>
Yes</span>

</xsl:if>

</xsl:template>

But if I put the test above in your code it doesn't change the attribute.
 
J

Jason Lehman

Ignore this I realize my error now. I had my statements backwards and now
it is working correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,244
Members
46,838
Latest member
KandiceChi

Latest Threads

Top