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

Re: XML Elements Tag (lable) Name is assign at run tim

Subject: Re: XML Elements Tag (lable) Name is assign at run time
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 3 Mar 2003 18:04:24 -0700 (MST)
lable
amit.parikh wrote:
> i have tested  2nd solution.
> i got error on this line
>     <xsl:key name="equiv" match="../element" use="element"/>

Sorry, I meant match="element" use="../element"

I also made an error in the named template. Here's an example that I tested.
The stylesheet looks for 'DOB' but because DOB is in the mapping file as being
equivalent to DateOfBirth, data can be obtained from the DateOfBirth element
in the source tree.

customer.xml
=============
<Customer>
  <Name>Amit</Name>
  <DateOfBirth>01/01/1970</DateOfBirth>
  <ZipCode>12121</ZipCode>
</Customer>


equivelem.xml
=============
<sourceMappings>
  <equivalentElementNames>   
    <element>DOB</element>
    <element>DateOfBirth</element>
  </equivalentElementNames>
  <equivalentElementNames>  
    <element>ZipCode</element>
    <element>PostCode</element>
  </equivalentElementNames>
</sourceMappings>


test.xsl
=============
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="no"/>

  <xsl:key name="equiv" match="element" use="../element"/>

  <xsl:variable name="mappings" select="document('equivelem.xml')/sourceMappings"/>

  <xsl:template match="Customer">
    <result>
      <xsl:call-template name="get-childElem-stringValue">
        <xsl:with-param name="childElem-name" select="'DOB'"/>
      </xsl:call-template>
    </result>
  </xsl:template>

  <xsl:template name="get-childElem-stringValue">
    <xsl:param name="childElem-name"/>
    <xsl:variable name="currentNode" select="."/>
    <xsl:for-each select="$mappings">
      <xsl:variable name="elements" select="key('equiv',$childElem-name)"/>
      <xsl:value-of select="$currentNode/*[local-name()=$elements]"/>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>



result of applying test.xsl to customer.xml with Saxon 6.5.2:
=============================================================
<?xml version="1.0" encoding="utf-8"?><result>01/01/1970</result>


Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 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.