the same way you can do the following...
<xsl:for-each select="catalog/cd[artist='Bob Dylan']">
Can you do the same filtering with the Value-Of statement?
<xsl:value-of select="value[name='Name']" />
Thanks, james.
Edit:
Sorry for the confusion.
I had some XML:
<DynamicData>
<item>
<name>Name</name>
<value xsi:type="xsd:int">0</value>
</item>
<item>
<name>Value</name>
<value xsi:type="xsd:long">9</value>
</item>
</DynamicData>
I wanted to use a filter on my value-of select, much in the same way as is possible when doing a for-each. I've only just started looking at XSLT, so wasnt sure of its abilities. In the end i used the following XSLT:
<set>
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="item[name='Name']/value=0">Low</xsl:when>
<xsl:when test="item[name='Name']/value=1">Medium</xsl:when>
<xsl:when test="item[name='Name']/value=2">High</xsl:when>
</xsl:choose>
</xsl:attribute>
...
The problem I was having was i was putting the filter after the value element in the test, like so. <xsl:when test="item/value[name='Name']=2">High</xsl:when>
Obviously the 'name' element isnt an element of 'value' but an element of 'item' hence why this didnt work.
Thanks for your help everyone, i got there in the end :)
Yes, select takes an XPATH expression as it's argument
XSL:value-of
Whilst the specification states you can, it could depend on the implementation your XML/XSL engine.
Remember that in XSLT 1.0
<xsl:value-of select="someNodeSet"/>
outputs only the string value of the first node insomeNodeSet
On the other side:
outputs the string value of every node in
someNodeSet
.Do note that in XSLT 1.0 you can workaround this with
xsl:copy-of
andtext()
test node.Example, given this input:
You can use
xsl:copy-of
as follows:will return the value of all the matching nodes exactly as in: