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

Re: Converting attributes into child elements

Subject: Re: Converting attributes into child elements
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Sat, 11 Nov 2000 09:52:39 -0800
xsl convert attribute to element
Here's an example from my book, taken from
the section called "The Talented Identity Transformation".
Hope it helps...

<!-- AttrToElement.xsl: Turn all attributes into subelements -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <!-- Import the identity transformation. -->
  <xsl:import href="Identity.xsl"/>
  <xsl:strip-space elements="*"/>
  <xsl:output indent="yes"/>
  <!-- Match any Attribute and turn it into an element -->
  <xsl:template match="@*">
    <xsl:element name="{name(.)}"><xsl:value-of select="."/></xsl:element>
  </xsl:template>
</xsl:stylesheet>


The base "Identity.xsl" transformation, imported by
the AttrToElement.xsl stylesheet above, looks like this:

<!-- The Identity Transformation -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Whenever you match any node or any attribute -->
  <xsl:template match="node()|@*">
    <!-- Copy the current node -->
    <xsl:copy>
      <!-- Including any attributes it has and any child nodes -->
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/

----- Original Message ----- 
From: <jlangdon@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxx>
Sent: Saturday, November 11, 2000 8:38 AM
Subject: Converting attributes into child elements


| Hello All,
| 
| I need some help with a transformation.  I would like to take an element
| with multiple attributes and convert them so the attributes are now child
| elements of the original element.  See example.
| 
| <contactInfo>
| <person fname="John" lname="Doe" address="123 Main Street" 
| city="Princeton"
| zipcode="08800">
| <person fname="John" lname="Doo" address="456 Main Street" city="Trenton"
| zipcode="08801">
| <person fname="John" lname="Doh" address="789 Main Street" 
| city="Jamesburg"
| zipcode="08802">
| </contactInfo>
| 
| Convert to
| 
| <contactInfo>
|   <person>
|     <fname>John</fname>
|     <lname>Doe</lname>
|     <address>123 Main Street</address>
|     <city>Princeton</city>
|     <zipcode>08800</zipcode>
|   </person>
|   <person>
|     <fname>John</fname>
|     <lname>Doo</lname>
|     <address>456 Main Street</address>
|     <city>Trenton</city>
|     <zipcode>08801</zipcode>
|   </person>
|   <person>
|     <fname>John</fname>
|     <lname>Doh</lname>
|     <address>789 Main Street</address>
|     <city>Jamesburg</city>
|     <zipcode>08802</zipcode>
|   </person>
| </contactInfo>
| 
| Any direction would be greatly appreciated.
| 
| TIA,
| 
| Jeff Langdon
| Web Programmer
| LTA Group, Inc
| Jamesburg, NJ 08831
| 
| 
| ---------------------------------------------
| This message was sent using MI-Webmail.
| No matter where you are, never lose touch.
| Get your Email using MI-Webmail.
| http://www.monmouth.com/
| 
| 
| 
|  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| 


 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.