Subject: Re: [xsl] problem building a lookup table and find match from a different template From: "Leslie Young" <xlr8sx@xxxxxxxxxxx> Date: Wed, 30 Aug 2006 15:19:39 -0500 |
From: Florent Georges <darkman_spam@xxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] problem building a lookup table and find match from a different template
Date: Wed, 30 Aug 2006 20:09:18 +0200 (CEST)
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] problem building a lookup, Florent Georges | Thread | Re: [xsl] problem building a lookup, Florent Georges |
Re: [xsl] Optimization of style she, meenakshi n | Date | Re: [xsl] problem building a lookup, Florent Georges |
Month |