Subject: Re: [xsl] Flattening hierarchic xml, retaining some structure From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 19 Jan 2005 18:09:33 -0500 |
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <xsl:apply-templates select="//subnode[not(mynode)]"/> <!-- Reach down and grab all the subnodes that are candidates for promotion. --> </xsl:template>
<xsl:template match="subnode" mode="tuck"> <xsl:copy-of select="."/> <xsl:apply-templates select="following-sibling::subnode[1]" mode="tuck"/> <!-- Step forward to the next sibling if there is one. --> </xsl:template>
<xsl:template match="subnode[mynode]" mode="tuck"/> <!-- When this template is matched, we're done tucking for now. -->
Cheers, Wendell
Hi, I have a hierarchic structure, that I would like to flatten.
I have tried looking for some examples, but I have not been able to expand the examples I have found, so that they will work on my problem.
(I have no influence on either input or output format, which is simplified here)
Regards, Ragulf Pickaxe :-)
Expanding on the example from David Pawson's site:
http://www.dpawson.co.uk/xsl/sect2/flatten.html
I have the following XML and would like to generate the flat structure as shown:
Input XML: <mynode name="xxx"> <subnode>Some text</subnode> <subnode> <mynode name="yyy"> <subnode><b>Some bold text</b></subnode> <subnode>Some text where some of it is <b>bold text</b></subnode> <subnode> <mynode name="zzz"> <subnode>Some text</subnode> <subnode>Some text</subnode> </mynode> </subnode> <subnode>Yet some text</subnode> </mynode> </subnode> <subnode>Some more text, <i>italic</i> is some of it</subnode> </mynode>
Output XML: <mynode name="xxx"> <subnode>Some text</subnode> <mynode name="yyy"> <subnode><b>Some bold text</b></subnode> <subnode>Some text where some of it is <b>bold text</b></subnode> </mynode> <mynode name="zzz"> <subnode>Some text</subnode> <subnode>Some text</subnode> </mynode> <mynode name="yyy"> <subnode>Yet some text</subnode> </mynode> <mynode name="xxx"> <subnode>Some more text, <i>italic</i> is some of it</subnode> </mynode>
I have tried some various forms of modes, and such, but alas no success, and no idea how to obtain success. The problem is with retaining the subnode under mynode structure, while also having the subnodes in the same document order as in the input.
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Flattening hierarchic xml, Ragulf Pickaxe | Thread | [xsl] Returning node-set from javas, Christof Schreuer |
[xsl] Can someone help me understan, Luke Shannon | Date | RE: [xsl] Comparing node for identi, Wendell Piez |
Month |