[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] Selecting the value from diff i/p XML
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Thu, 16 Sep 2010 21:37:22 +0200

On 16.09.2010 16:20, Shashank Jain wrote:

Thanks Gerrit, Hermann, Bauman and Mukul for helping me out.


The 3 argument Key function is really cool, but for some reason I am not getting any output with that.
I am trying to run that in the latest version of XML Spy and also tried using Saxon9he processor.

Maybe you specified version="1.0" instead of 2.0 in the xsl:stylesheet element, or you didn't use the modified xsl:key declaration (indexing both item and data elements)?


Mukul, I think you missed that I want to apply my XSLT on Root2.xml.
but thanks for your help :-)

If you really need to process root2.xml and need keys for performance, you may like this one:


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0"  >

  <xsl:output
    method="xml"
    indent="yes"
    />

  <xsl:key
    name="idlist"
    match="item"
    use="@id"
    />
  <xsl:variable
    name="data"
    select="document('Root1.xml')"
    as="document-node(element(root1))"
    />

  <!-- processing Root2.xml: -->
  <xsl:template match="/">
    <xsl:apply-templates
      select="$data/root1"
      mode="lookup-r1-values">
      <xsl:with-param name="root2" select="root2" />
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="root1" mode="lookup-r1-values">
    <xsl:param name="root2" as="element(root2)" />
    <xsl:for-each select="key('idlist', $root2/data/@id)">
      <xsl:value-of select="@value"/>
      <br/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

-Gerrit


Current Thread
Keywords