G
Guest
Hello. I am a newbie trying to get my first XLST script working. I already
know how to do this:
Source XML:
<category id="a0104">
<name>Oil and Gas</name>
</category>
XSLT:
<xsl:for-each select="category">
<p>
<input type="checkbox" />
<xsl:value-of select="name"/>
</p>
</xsl:for-each>
The output is:
<p><input type="checkbox">Oil and Gas</p>
But what if I wish to get the output?
<p><input type="checkbox" id="a0104"/>Oil and Gas</p>
I have experimented several times, it seems <xsl:value-of> can be only
used inside an element but cannot be used in element attribute string.
e.g. This will not work:
<xsl:for-each select="category">
<p>
<input type="checkbox" id="<xsl:value-of select=\"@id\"/>"/>
<xsl:value-of select="name"/>
</p>
</xsl:for-each>
P.S. I tried many tutorials and none of them cover this topic. The last
idea I can think of is to use
<input type="checkbox"><xsl:value-of select="name"/></input>
And later use a javascript:
inputs = document.getElementsByTagName("input");
for (var i=0; i < length(inputs); i++)
inputs.name = inputs.innerText;
know how to do this:
Source XML:
<category id="a0104">
<name>Oil and Gas</name>
</category>
XSLT:
<xsl:for-each select="category">
<p>
<input type="checkbox" />
<xsl:value-of select="name"/>
</p>
</xsl:for-each>
The output is:
<p><input type="checkbox">Oil and Gas</p>
But what if I wish to get the output?
<p><input type="checkbox" id="a0104"/>Oil and Gas</p>
I have experimented several times, it seems <xsl:value-of> can be only
used inside an element but cannot be used in element attribute string.
e.g. This will not work:
<xsl:for-each select="category">
<p>
<input type="checkbox" id="<xsl:value-of select=\"@id\"/>"/>
<xsl:value-of select="name"/>
</p>
</xsl:for-each>
P.S. I tried many tutorials and none of them cover this topic. The last
idea I can think of is to use
<input type="checkbox"><xsl:value-of select="name"/></input>
And later use a javascript:
inputs = document.getElementsByTagName("input");
for (var i=0; i < length(inputs); i++)
inputs.name = inputs.innerText;