|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: removing nesting in data structure
Andrew Welch wrote:
> <?xml version="1.0"?>
> <root>
> <para0>
> <para>para 0</para>
> <subpara1>
> <para>subpara 1</para>
> <subpara2>
> <para>subpara 2</para>
> <subpara3>
> <para>subpara 3</para>
> </subpara3>
> </subpara2>
> </subpara1>
> </para0>
> </root>
>
> Each subpara is a child of the preceding subpara, up to para0 which is
> the top level. The nested element will always be the last child of the
> parent. Now the structure I would like is more flat, like this:
>
> <root>
> <para0>
> <para>para 0</para>
> </para0>
> <subpara1>
> <para>subpara1</para>
> </subpara1>
> <subpara2>
> <para>subpara2</para>
> </subpara2>
> ...and so on
> </root>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="root">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="para0|*[starts-with(local-name(),'subpara')]">
<xsl:copy>
<xsl:copy-of select="para"/>
</xsl:copy>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="para|text()"/>
</xsl:stylesheet>
Alternatively, you can ditch the last template and replace the
<xsl:apply-templates/> in the 2nd template with
<xsl:apply-templates select="*[starts-with(local-name(),'subpara')]"/>
- Mike
____________________________________________________________________________
mike j. brown | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








