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

Re: elements to attributes

Subject: Re: elements to attributes
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 28 Feb 2003 16:23:53 -0500
Re:  elements to attributes
Hi Harsha,

At 02:23 PM 2/28/2003, you wrote:
and I need my result XML document to have all the attributes in each level
converted to elements at same level
Can there be a generic xsl which looks at all the nodes and does this?


There's a template described in the XSL Recommendation (http://www.w3.org/TR/xslt) as an "identity template", because it matches any node and just copies it, then picks its attributes and children to do the same:

<xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>

You need to split this in two: one to handle all nodes but attributes, the other to handle attributes:

<xsl:template match="node()">
    <xsl:apply-templates select="node()|@*"/>

Except the one for attributes should have instructions to make an element instead:

<xsl:template match="@*">
  <xsl:element name="{name()}">
    <xsl:value-of select="."/>

But if you try this out, you really should study up on the processing model (templates and apply-templates, and the default child:: axis) to make sure you understand it.

(Once you understand the technique, you also will know how to extend it, for example to move things around or change names -- or add things.)

The identity template (find it in the list archives under identity template or identity transformation, it's a FAQ too) is also the solution to the other problem you have posted. You may have already gotten a solution, or ask again if you need to and someone will give you a hint.


___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_ "Thus I make my own use of the telegraph, without consulting the directors, like the sparrows, which I perceive use it extensively for a perch." -- Thoreau

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

Current Thread


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.
First Name
Last Name
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.