views:

151

answers:

2

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:attribute 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?

A: 
<xsl:attribute name="style">
    <xsl:value-of select="hello" />
</xsl:attribute>
Rich
No, I was actually trying to put in the text "hello" just to illustrate my problem. I don't think that code you have will work either. I'm able to insert anything I want into any kind of attribute, but when it comes to the "style" attribute, nothing will show up. This only seems to happen for "style."
Corey
That code won't work because the value-of select will be trying to find an element called "hello".You would use this instead: <xsl:value-of select="'hello'"/> to make it clear you want the raw text.
Alan Christensen
+1  A: 

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.

Alohci
As an aside: Literal attribute notation is less wordy `<li style="color:red"></li>` - `<xsl:attribute>` has it's uses, but in this example it is wasted.
Tomalak