xml - How to find element that matches xslt attribute value in for-each loop -
suppose have next 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 want print name
attributes of element bar
point element foo
has attribute checked
. illustration above, xslt output blub
, plim
.
here have tried far check whether can print id
attribute of foo
element 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 no avail. think problem is, check foo[@id=./@for]
select both @id
, @for
foo
element. how can want @for
attribute current element in loop @id
other current element?
how can want @for
attribute current element in loop @id
other current element?
use the current()
function:
<xsl:value-of select="../../foos/foo[@id=current()/@for]/@id" />
inside square brackets, .
node predicate testing, whereas current()
node current target of for-each
.
xml xslt
No comments:
Post a Comment