[xsl] XML tags to XML attributes with XSL

Subject: [xsl] XML tags to XML attributes with XSL
From: lbertin@xxxxxxxxxxxx
Date: Wed, 22 Oct 2003 09:48:55 +0200
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


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

<?xml version="1.0" encoding="iso-8859-9"?>
<Message id="14245" name="ACCEPTTASKS" userid="bertin" dateemission

Here is my XSL :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl
<xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/>

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

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


XML Result :

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

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