xml tree to flat xml

Here should go questions about transforming XML with XSLT and FOP.
whiteadi
Posts: 2
Joined: Tue Nov 14, 2006 6:11 pm
Contact:

xml tree to flat xml

Post by whiteadi »

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
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="*">
<xsl:copy/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
whiteadi
Posts: 2
Joined: Tue Nov 14, 2006 6:11 pm
Contact:

Post by whiteadi »

Resolved,an root must be given.(James Durning did it)

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>

I see now that also jkmyoung manage to get the answer, seems was not to complicated, 10x man!
Post Reply