[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: problem building a lookup table and find match fro

Subject: Re: problem building a lookup table and find match from a different template
From: Florent Georges <darkman_spam@xxxxxxxx>
Date: Wed, 30 Aug 2006 20:09:18 +0200 (CEST)
Re:  problem building a lookup table and find match fro
Leslie Young wrote:

  Hi

> What I need to do is to process 2 elements in a xml:
> dataset1 and dataset2.  If same id exists in dataset2,
> display warning, then display the value from dataset2. If
> not found in dataset2, display dataset1 value.

  You don't need to use a variable for this.  Dynamically
build trees in XSLT 1.0 (Result Tree Fragments) have a
boring restriction: you can't navigate in their structure as
you can for the input tree.  You can just copy them in the
output.  But you can use keys:

    <xsl:key name="ds2" match="Dataset2/Item" use="@ID"/>

    <xsl:template match="/">
      <xsl:apply-templates select="Dataset1/Item" mode="dispatch"/>
    </xsl:template>

    <xsl:template match="Item" mode="dispatch">
      <xsl:variable name="item2" select="key('ds2', @ID)"/>
      <xsl:choose>
        <xsl:when test="$item2">
          <xsl:apply-templates select="$item2"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <xsl:template match="Dataset1/Item">
      In 1: <xsl:value-of select="."/>
    </xsl:template>

    <xsl:template match="Dataset2/Item">
      [warn] In 2: <xsl:value-of select="."/>
    </xsl:template>

  Warning: not tested, and written in my MUA...

  Regards,

--drkm

























	
 p5.vert.ukl.yahoo.com uncompressed/chunked Wed Aug 30 12:13:39 GMT 2006 
	
		
___________________________________________________________________________ 
Dicouvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet ! 
Yahoo! Questions/Riponses pour partager vos connaissances, vos opinions et vos expiriences. 
http://fr.answers.yahoo.com 

Current Thread

Purchase Stylus Studio Online Today!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.