I have the following problem:
Within a stylesheet document I want to create an output from a relativly simple xml file.
While most of the common XPath and XSLT stuff is not that difficult, comparing two elements and deciding, how to go on is quite a problem right now.
example xml:
<root>
<foo>
<value>1</value>
<name>foo1</name>
</foo>
<foo>
<value>2</value>
<name></name>
</foo>
<foo>
<value>3</value>
<name>foo3</name>
</foo>
<bar>
<value>1</value>
</bar>
<bar>
<value>2</value>
</bar>
</root>
within the stylesheet is a xsl:for loop, that tries to decide, whether or not the current node shall be displayed:
[...]
<xsl:for-each select="bar">
<xsl:if test="//foo[value=./value]/name">
<!-- go on, if the content of the 'name' element is not empty -->
</xsl:if>
</xsl:for-each>
[...]
The intention was only to go on with the stuff, if the content of the ‘name’ element from ‘foo’ is not empty, using the euqality of the ‘value’ element.
The result is, that every line from ‘bar’ creates an output, event if I intended not to have one for the second entry, since ‘//foo[2]/name’ is empty.
I’m not sure, how to proceed at the moment… Maybe a generated key would be sufficent!? I don’t know…
Thanks for every comment!
You probably want to use something like the following:
Most striking is of course that you should use current()/value instead of ./value, because current() refers to the bar element, and . refers to the foo element looped over.
When applied to the input supplied, this gives