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

Re: xsl:transform

Subject: Re: xsl:transform
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 22 Jun 2001 22:11:36 -0700 (PDT)
header2 in xsl
Benoit_Aumars@xxxxxxxxxxxx wrote:
>
>I would like to transform from one xml into another one
>using a 'lookup'  xml file.
>
>Here is the original xml file :
>
><?xml version="1.0"?>
><file1>
>    <col1>01</col1>
>    <col2>Hello</col2>
>    <col3>world</col3>
>    <col4>GTP</col4>
>    <col5>02 Jul 1999 09:45:05:706</col5>
></file1>
>
>using this 'lookup' xml file :
><?xml version="1.0"?>
><xref>
>    <file1>
>	<abbr>col1</abbr><name>label1</name>
>	<abbr>col2</abbr><name>label2</name>
>	<abbr>col3</abbr><name>label3</name>
>	<abbr>col4</abbr><name>label4</name>
>	<abbr>col5</abbr><name>label5</name>
>    </file1>
>    <file2>
>	<abbr>col1</abbr><name>header1</name>
>	<abbr>col2</abbr><name>header2</name>
>    </file2>
></xref>
>
>
>the xml result is :
><?xml version="1.0"?>
><file1>
>    <label1>01</label1>
>    <label2>Hello</label2>
>    <label3>world</label3>
>    <label4>GTP</label4>
>    <label5>02 Jul 1999 09:45:05:706</label5>
></file1>
>
>If the original xml file :
>
><?xml version="1.0"?>
><file2>
>    <col1>12345</col1>
>    <col2>Welcome</col2>
></file2>
>
>using the same 'lookup' xml file, the result is :
><?xml version="1.0"?>
><file2>
>    <header1>12345</header1>
>    <header2>Welcome</header2>
></file2>
>
>Any idea how to ?


Hi Ben,

Use the same solution as I posted yesterday 
(http://sources.redhat.com/ml/xsl-list/2001-06/msg01004.html)

You've changed a little the problem -- the input arguments are elements -- not
attributes as before. More importantly, your lookup file now has different sections
and you specify (the name of the top element of the input xml file) the name of the
section that must be used in the lookup.

Therefore, the previous solution is changed accordingly:

<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:variable name="lookupSection" select="name(/*)"/>
  
  <xsl:template match="/">
    <xsl:element name="{name(*)}">
      <xsl:apply-templates select="/*/*"/>
    </xsl:element>
  </xsl:template>

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

This, as the previous solution, has been tested and verified to work as expected.

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.