[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Flattening hierarchic xml, retaining some structur
Tempore 15:56:08, die 01/19/2005 AD, hinc in
xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Ragulf Pickaxe
<jawxml@xxxxxxxxxxx>:
I have a hierarchic structure, that I would like to flatten.Hi, The followng stylesheet will do the job when applied to the sample XML. It most likely needs some modification to fit the real XML. <?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="mynode"> <xsl:apply-templates select="*[not(child::mynode)][position()=1 or preceding-sibling::*[1]/child::mynode]" mode="encapsule"/> <xsl:apply-templates select="../following::*[1]/mynode"/> </xsl:template> <xsl:template match="mynode/*" mode="encapsule"> <mynode> <xsl:copy-of select="../@*"/> <xsl:apply-templates select="." mode="list"/> </mynode> <xsl:apply-templates select="(following-sibling::*/mynode)[1]"/> </xsl:template> <xsl:template match="mynode/*" mode="list"> <xsl:copy-of select="."/> <xsl:apply-templates select="following-sibling::*[1][not(child::mynode)]" mode="list"/> </xsl:template> </xsl:stylesheet>
|
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
|