|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: choose to define conditional attributes?
> <label>
> <xsl:attribute name="id">myLabelId</xsl:attribute>
> <xsl:choose>
> <xsl:when test=". = ''">
> <xsl:attribute name="style">MyStyleEmpty</xsl:attribute>
> </xsl:when>
> <xsl:otherwise>
> <xsl:attribute name="style">MyStyleFull</xsl:attribute>
> </xsl:otherwise>
> </xsl:choose>
> The Label
> </label>
http://www.w3.org/TR/xslt#creating-attributes says, "Instantiating an
xsl:attribute element adds an attribute node to the containing result
element node". It's not terribly clear, but the "containing" node is the
<xsl:attribute>'s parent, which is <xsl:when> in your example. You want the
parent to be a result element, i.e. a literal result element like <label> or
an <xsl:element> instruction.
Furthermore, <xsl:choose>...</xsl:choose> gets replaced by characters. If
there were some non-whitespace characters in the <xsl:when> or
<xsl:otherwise>, you'd end up with those being inserted right before " The
Label" in the content of <label>. You really want the characters to end up
inside your <xsl:attribute>.
Try it this way instead:
<label>
<xsl:attribute name="id">myLabelId</xsl:attribute>
<xsl:attribute name="style">
<xsl:choose>
<xsl:when test=". = ''">
<xsl:value-of select="'MyStyleEmpty'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'MyStyleFull'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
The Label
</label>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








