| Subject: Re: [xsl] 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) | 
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 | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] XML Elements Tag (lable) , Mike Brown | Thread | [xsl] embedded xslt with xsl:includ, Joe Meree | 
| [xsl] input type radio checked, Dionisio Ruiz de Zar | Date | RE: [xsl] tu put one value into the, Lopez, William | 
| Month |