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

Re: HOWTO : Lookup tables

Subject: Re: HOWTO : Lookup tables
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 22 Jun 2001 03:40:25 -0700 (PDT)
tables xml
Benoit Aumars wrote:
> 
> I'm looking for a sample code to transform one xml file into another one 
> using a 'lookup tables' xml file.
> Suppose I have this before.xml :
> 
> <?xml version="1.0"?>
> <in>
>     <A code1="01" code2="Hello" />
>     <A code1="02" code2="world" />
> </in>
> 
> and I want to transform it into after.xml :
> <?xml version="1.0"?>
> <in>
>     <Label1>01</Label1>
>     <Label2>Hello</Label2>
>     <Label1>02</Label1>
>     <Label2>world</Label2>
> </in>

> using this 'lookup tables' xml file ( something like this / similar to this
> ) :
> <?xml version="1.0"?>
> <lookup>
>     <abbr>code1</abbr><name>Label1</name>
>     <abbr>code2</abbr><name>Label2</name>
> </lookup>
> 
> Can someone help me out please ?

The following stylesheet produces your desired output when applied on your xml
source:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" omit-xml-declaration="yes"/>
  <xsl:key name="kLookup" match="name" use="preceding-sibling::abbr[1]"/>

  <xsl:template match="/">
    <in>
      <xsl:apply-templates select="in/A/@*"/>
    </in>
  </xsl:template>

  <xsl:template match="A/@*">
     <xsl:variable name="input" select="."/>
     <xsl:for-each select="document('lookup.xml')">
        <xsl:for-each select="key('kLookup', name($input))">
          <xsl:element name="{.}">
           <xsl:value-of select="$input"/>
          </xsl:element>
        </xsl:for-each>
     </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

Cheers,
Dimitre Novatchev.




__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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-2013 All Rights Reserved.