XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Adrian AlbuSubject: xml tree to flat xml
Author: Adrian Albu
Date: 14 Nov 2006 10:22 AM
Hi,

I have an "normal" xml,

a structure like

<x ...>
<y ...>
<z ...>
</z>
</y>
</x>

and I want to have a "flat" xml

<x .../>
<y .../>
<z .../>
so each node with its name and all attributes with original valus just not tree but with nodes not imbricated.(I have the unique ids already to know parent-child).

I try something like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="x | y | z">
<xsl:text>< </xsl:text>
<xsl:value-of select="name(.)" />
<xsl:for-each select="@*">
<xsl:value-of select="name()" />=<xsl:value-of select="." />
</xsl:for-each>
<xsl:text disable-output-escaping="yes"> /></xsl:text>
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
</xsl:stylesheet>

but have the error on <xsl:text>< </xsl:text>.

Best regards,
white

Postnext
James DurningSubject: xml tree to flat xml
Author: James Durning
Date: 14 Nov 2006 11:27 AM
<xsl:template match="*">
<xsl:copy><xsl:copy-of select="@*"/></xsl:copy>
<xsl:apply-templates/>
</xsl:template>

Posttop
Adrian AlbuSubject: xml tree to flat xml
Author: Adrian Albu
Date: 14 Nov 2006 12:22 PM
Originally Posted: 14 Nov 2006 11:52 AM
Yes it works except an root must be given.

Like this:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<ENHANCED>
<xsl:apply-templates />
</ENHANCED>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>

Thanks man!!!

Was simple I see.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.