JohnSixkiller
asked on
XSL XPATH condition in attribute value
Hi, experts
is there any way to use conditions in XSL/XPATH in attribute's value?
I need something like this:
...
<div id='lr-{@id}' style="display:{IF @expanded='yes' THEN 'block' ELSE 'none'}">
...
At this time I have this code:
But with more variables comes lot of code. :(
is there any way to use conditions in XSL/XPATH in attribute's value?
I need something like this:
...
<div id='lr-{@id}' style="display:{IF @expanded='yes' THEN 'block' ELSE 'none'}">
...
At this time I have this code:
But with more variables comes lot of code. :(
<xsl:variable name="visibility">
<xsl:choose>
<xsl:when test="@expanded='yes'">
<xsl:value-of select="'block'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'none'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
sorry, drop the last line
ASKER
Thank you for quick response, can you give me an example of XPATH2 version?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, thanks for your time.
welcome
the code would not be far off from what you have in your pseudo code
In XSLT1, you would need the xsl:choose approach
very close to what you did, except that you don't necessarily need the variable, you could use an xsl:attribute
<div id='lr-{@id}'>
<xsl:attribute name="style=">
<xsl:text>display:</xsl:te
<xsl:choose>
<xsl:when test="@expanded='yes'">
<xsl:text>block</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>none</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
{IF @expanded='yes' THEN 'block' ELSE 'none'}">