xml tree to flat xml
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Tue Nov 14, 2006 6:11 pm
- Contact:
xml tree to flat xml
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
-
- Posts: 89
- Joined: Mon Mar 06, 2006 10:13 pm
<?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>
<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>
-
- Posts: 2
- Joined: Tue Nov 14, 2006 6:11 pm
- Contact:
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!
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!
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service