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

XML tags to XML attributes with XSL

Subject: XML tags to XML attributes with XSL
From: lbertin@xxxxxxxxxxxx
Date: Wed, 22 Oct 2003 09:48:55 +0200
xsl xml attribute
Hello to the list !

I'm having a problem with XSL, i've done a lot of searching to find
the solution but it seems i'm stuck now. I hope you'll help me out
with the problem.

Here it goes, i have xml data which can contains tags like this

<Attributes>
<nom>toto</nom>
<valeur>123</valeurs>
</Attributes>

I want to parse it and make it become attributes of the parent node.
Which means, if the parent node is <Process> i will get :

<Process toto="123">

Here is an XML exemple and the xsl i've done with the result it
provides.

<?xml version="1.0" encoding="iso-8859-9"?>
<Message id="14245" name="ACCEPTTASKS" userid="bertin" dateemission
="15/10/2003">
<Process>
<Attributes>
<nom>id2</nom>
<valeur>4321</valeur>
</Attributes>
<Task>
<Attributes>
<nom>id</nom>
<valeur>1243</valeur>
</Attributes>
</Task>
</Process>
</Message>

Here is my XSL :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl
="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>

<xsl:template match="*">
     <xsl:copy>
          <xsl:apply-templates select="Attributes"/>
          <xsl:apply-templates select="* | text()"/>
     </xsl:copy>
</xsl:template>

<xsl:template match="Attributes">
     <xsl:variable name="nomattr" select="nom"/>
     <xsl:attribute name="{$nomattr}">
          <xsl:value-of select="valeur"/>
     </xsl:attribute>
</xsl:template>

</xsl:stylesheet>

XML Result :

<?xml version="1.0" encoding="ISO-8859-1"?>
<Message>
<Process id2="4321">
<Task id="1243"/>
</Process>
</Message>

As you can see, my attributes of <Message> have been stripped. I'm pretty
sure there is a more proper way to do what i want but i cant find it.

Any help would be very much appreciated !

Thanks a lot !

Laurent Bertin


 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.