[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Flat XML to hierarchical output ...

Subject: RE: Flat XML to hierarchical output ...
From: christoph.naber@xxxxxxxxxxxxxxxxxxx
Date: Tue, 21 Aug 2007 09:31:28 +0200
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.