[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Flat XML to hierarchical output ...
Hello, > Although the XML is not hierarchical there is a hierarchy required in > output ie > HEADER > LINES > TOTAL > In my current understanding of your problem I think you are trying to aggregate the <LINE> nodes that directly follow a <HEADER> node into one <LINES> node. <HEADER /> <LINES> <LINE /> <LINE /> </LINES> <TOTAL /> This is possible with recursive templates. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="REPORT"> <REPORT> <xsl:apply-templates select="HEADER | TOTAL" /> </REPORT> </xsl:template> <xsl:template match="HEADER"> <xsl:copy-of select="." /> <LINES> <xsl:apply-templates select="following-sibling::*[1][self::LINE]" mode="more2come"/> </LINES> </xsl:template> <xsl:template match="TOTAL" > <xsl:copy-of select="." /> </xsl:template> <xsl:template match="LINE" mode="more2come"> <xsl:copy-of select="." /> <xsl:apply-templates select="following-sibling::*[1][self::LINE]" mode="more2come" /> </xsl:template> </xsl:stylesheet> OUTPUT (stylesheet applied to the given sample input) <?xml version="1.0"?> <REPORT> <HEADER/> <LINES> <LINE/> </LINES> <TOTAL/> <HEADER/> <LINES> <LINE/> </LINES> <TOTAL/> <HEADER/> <LINES> <LINE/> <LINE/> <LINE/> </LINES> <TOTAL/> </REPORT> Greetings Christoph If you are not the intended addressee, please inform us immediately that you have received this e-mail by mistake and delete it. We thank you for your support.
|
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
|