Re: [xsl] Selecting the value from diff i/p XML

Subject: Re: [xsl] Selecting the value from diff i/p XML
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Thu, 16 Sep 2010 01:00:01 +0200
Gerrit,

good solutions.

While the simpler with Root1.xml as input is to prefer it
is also XSLT 1.0.

I modified your other solution in order to emulate 3-argument
XPath2 key function in XSLT 1.0:

   <xsl:template match="/">
-    <xsl:for-each select="key(
-                            'idlist',
-                            key('idlist', $data/root1/item/@id)/@id,
-                            $data
-                          )
-                          ">
-      <xsl:value-of select="@value"/>
-      <br/>
+    <xsl:variable name="ids"
+                  select="key('idlist', $data/root1/item/@id)/@id"/>
+    <xsl:for-each select="$data">
+      <xsl:for-each select="key(
+                              'idlist',
+                              $ids
+                            )
+                            ">
+        <xsl:value-of select="@value"/>
+        <br/>
+      </xsl:for-each>
     </xsl:for-each>
   </xsl:template>



$ xsltproc 2.xsl Root1.xml
A<br/>C<br/>E<br/>F<br/>H<br/>I<br/>J<br/>
$
$ saxon 1.xsl Root2.xml ; echo
A<br/>C<br/>E<br/>F<br/>H<br/>I<br/>J<br/>
$
$ xsltproc 1a.xsl Root2.xml
A<br/>C<br/>E<br/>F<br/>H<br/>I<br/>J<br/>
$



Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
Fixpack team lead
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



From:       "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
To:         xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Date:       09/15/2010 11:54 PM
Subject:    Re: [xsl] Selecting the value from diff i/p XML





On 15.09.2010 23:51, Imsieke, Gerrit, le-tex wrote:
> You key function returns the elements of Root2.xml whose id matches
> those of the Root1 items.
>
> But ultimately you want to lookup the value attributes of the
> corresponding Root1 elements.
>
> If you really want to process root2.xml as primary source, you may try
> this (XPath2's 3-argument key function involved):
In fact, it's the XSLT2 and not an XPath2 key function:
http://www.w3.org/TR/xslt20/#function-key

Current Thread