xsl-list
[Top] [All Lists]

Re: How to change element nodes cases?

2003-03-30 19:58:43
At 2003-03-30 17:42 -0800, Michael Liwanag wrote:
How can I change this form:
<customer> Michael </customer>
to
<Customer> Michael </Customer>

Remember with XSLT you are *not* changing nodes, you are building a result tree of nodes out of the source tree of nodes.

Therefore, in the push model, assuming you want attributes and content preserved, you would have a template for the result matched to the named node in the source:

  <xsl:template match="customer">
     <Customer>
       <xsl:copy-of select="@*"/>
       <xsl:copy-of select="node()"/>
     </Customer>
  </xsl:template>

If, however, you are changing the name on the way to the result while preserving the attributes, but also changing the names of other nodes on the way to the result, then you will need it to be slightly different as in the following modified node identity transform:

  <xsl:template match="@*|node()"><!--node identity transform-->
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="customer">
     <Customer>
      <xsl:apply-templates select="@*|node()"/>
     </Customer>
  </xsl:template>
  ... other node templates follow...

(I haven't checked the above for typos....)

I hope this helps.

................ Ken


--
Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO
                             North America:      June 16-20, 2003

G. Ken Holman                mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999 (F:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 0-13-140374-5                              Definitive XSL-FO
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-10-1              Practical Formatting Using XSL-FO
Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc


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



<Prev in Thread] Current Thread [Next in Thread>