Cross matching
This is an open discussion with 2 replies, filed under XSLT.
Search
You're accessing wrong context. When you apply the cross-reference xPath, you need current()
function to access current context. See Implementation #1
below.
I strongly recommend Implementation #2
.
<shop> <entry id="123"> <title>FOO</title> <prov> <item id="1710">bla-bla</item> </prov> </entry> <entry id="456"> <title>BAR</title> <prov> <item id="1522">bla-bla</item> </prov> </entry> </shop> <prov-list> <entry id="1522"> <initials>KD</initials> </entry> <entry id="1710"> <initials>SV</initials> </entry> </prov-list> <!-- Implementation #1: Access current context using `current()` <ul> <xsl:for-each select="/data/shop/entry"> <li> <xsl:value-of select="title"/> <xsl:text> - </xsl:text> <xsl:value-of select="/data/prov-list/entry[ @id = current()/prov/item/@id ]/initials"/> </li> </xsl:for-each> </ul> <!-- Implementation #2: Use variables for easier understanding <ul> <xsl:for-each select="/data/shop/entry"> <xsl:variable name="shopEntry" select="."/> <xsl:variable name="provEntry" select="/data/prov-list/entry[ @id = $shopEntry/prov/item/@id ]"/> <li> <xsl:value-of select="$shopEntry/title"/> <xsl:text> - </xsl:text> <xsl:value-of select="$provEntry/initials"/> </li> </xsl:for-each> </ul>
Thanks Vlad, now it works...
Create an account or sign in to comment.
Hi,
I have a datasource generating xml like this:
Then I have another datasource like this:
I tried to do
(the context being
shop
)Still I manage to do
Thanks!