setting the style attribute of a li element using xsl
I'm using an XSL file to transform a XML file to a XHTML file. I am trying to create an element li and set the "style" attribute to the value "hello:"
<li><xsl:a开发者_开发百科ttribute name="style">hello</xsl:attribute></li>
I get:
<li style=""></li>
But was expecting to get:
<li style="hello"></li>
Anybody have any idea what's going on?
You can work this out with following way
<xsl:attribute name="class">
<xsl:value-of select="'selected'"/>
</xsl:attribute>
The above example is for adding class to the li tag. If you are too specific for using the style tag inside li then use
<xsl:attribute name="style">
<xsl:value-of select="'color:green;'"/>
</xsl:attribute>
It seems Firefox checks the values going into the style attribute. if you put "color:red", for example, instead of "hello", that will be accepted into the style attribute. Invalid css is discarded.
It may depend on how exactly you are inspecting the contents of the style attribute, since its hard to see the result of the transformation without inspecting the DOM, which will be a sanitized version of the transformation.
精彩评论