Re: [xsl] XML Elements Tag (lable) Name is assign at run time

Subject: Re: [xsl] XML Elements Tag (lable) Name is assign at run time
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 3 Mar 2003 02:01:34 -0700 (MST)
amit.parikh wrote:
> <!-- change tag from ZipCode to PostCode -->
>     <PostCode></PostCode>
>  
> is there any solution which can solve problem with out rewriting XSL
> Template again??

option 1:

<xsl:value-of select="ZipCode|PostCode"/>

xsl:value-of creates a text node using the string-value of the node that comes
first in document order, of all the nodes identified in the expression, which
in this case is the union of all ZipCode and PostCode children of the current
node.


option 2 (untested):

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:data="urn:dummy-non-null-ns">

  <xsl:output method="html"/>

  <!--
    This could be in an external document, if you wanted:
    Just adjust the $mappings source, below.
  --> 
  <data:sourceMappings>
    <equivalentElementNames>
      <element>DOB</element>
      <element>DateOfBirth</element>
    </equivalentElementNames>
    <equivalentElementNames>
      <element>ZipCode</element>
      <element>PostCode</element>
    </equivalentElementNames>
  </data:sourceMappings>

  <xsl:variable name="mappings"
    select="document('')/xsl:stylesheet/data:sourceMappings"/>

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

  <xsl:template match="Customer">
    <table>
      <tr>
        <td>Date Of Birth:</td>
        <td>
          <xsl:call-template name="get-childElem-stringValue">
            <xsl:with-param name="childElem-name" select="'DOB'"/>
          </xsl:call-template>
        </td>
      </tr>
      <!-- (use same approach for all other rows) -->
    </table>
  </xsl:template>

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

</xsl:stylesheet>

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