xsl-list
[Top] [All Lists]

Re: [xsl] problem building a lookup table and find match from a different template

2006-08-30 11:09:44
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 
        
                
___________________________________________________________________________ 
Découvrez un nouveau moyen de poser toutes vos questions quelque soit le sujet 
! 
Yahoo! Questions/Réponses pour partager vos connaissances, vos opinions et vos 
expériences. 
http://fr.answers.yahoo.com 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--