xml tree to flat xml
Posted: Tue Nov 14, 2006 6:12 pm
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
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