xml - How to use XSL to create HTML attributes? -
why using xml data style html tags illegal? example:
<li style="width:<xsl:value-of select="width"/>px">
why can't this? there alternative methods out there?
why can't this?
<li style="width:<xsl:value-of select="width"/>px">
because xsl xml itself. , anything… not xml.
you mean attribute value template:
<li style="width:{width}px">
or explicit form, more complex expressions:
<li> <xsl:attribute name="style"> <xsl:choose> <xsl:when test="some[condition = 'is met']">thisvalue</xsl:when> <xsl:otherwise>thatvalue</xsl:otherwise> </xsl:choose> </xsl:attribute> </li>
or dynamic attribute names (note attribute value template in name):
<li> <xsl:attribute name="{$attrname}">somevalue</xsl:attribute> </li>
additional note: attributes must created before other child nodes. in other words, keep <xsl:attribute>
@ top.
Comments
Post a Comment