Suppose I have the following XML:
<data>
<foos>
<foo id="1" checked="yes" />
<foo id="2" />
<foo id="3" />
<foo id="4" checked="yes" />
</foos>
<bars>
<bar for="1" name="blub" />
<bar for="2" name="bla" />
<bar for="3" name="baz" />
<bar for="4" name="plim" />
</bars>
</data>
Now I want to print all the name
attributes of those element bar
which point to an element foo
that has the attribute checked
. So for the example above, my xslt would output blub
and plim
.
Here is what I have tried so far is to just check whether I can print the id
attribute of the foo
element that each bar
belongs to:
<xsl:template match="/">
<xsl:for-each select="//bars/bar">
<xsl:value-of select="../../foos/foo[@id=./@for]/@id" />
</xsl:for-each>
</xsl:template>
but to no avail. I think the problem is, that the check foo[@id=./@for]
will select both @id
and @for
from the foo
element. So how can I say that I want the @for
attribute from my current element in the for loop but the @id
from the other current element?