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

XML Reorganisation

Subject: XML Reorganisation
From: Andrew Timberlake <andrew.lists@xxxxxxxxx>
Date: 22 May 2002 12:29:31 +0200
department reorganisation template
Please could someone help with this transformation.

I have the following XML:
<root>
  <province name="">
    <area name="">
      <city name="">
        <department type="">
          <hc>34987</hc><!-- numeric values -->
          <nl>8346</nl><!-- numeric values -->
          <p>547568</p><!-- numeric values -->
        </departmen>
        ...
      </city>
      ...
    </area>
    ...
  </province>
  ...
</root>

I am trying to create the following output:

<root>
  <national>
    <department type="">
      <province name="">
        <hc>[sum of all hc within province of 
		particular department type]</hc>
        [repeated for sums of nl & p]
      </province>
      ... repeat for all provinces
    </department>
    ... do for each department
  </national>
  <province name="">
    <department type="">
      <area name="">
        <hc>[sum of all hc within areas of 
		particular department type]</hc>
        [repeated for sums of nl & p]
      </area>
      ... repeat for all areas within province
    </department>
    ... do for each department
  </province>
  ... do for each province
  <area name="">
    <department type="">
      <city name="">
        <hc></hc>
        [repeated for nl & p]
      </city>
      ... repeat for all cities within area
    </department>
    ... do for each department
  </area>
  ... do for each area
</root>

I am trying to achieve this as follows.
* I match the root node.
* I create a unique list of departments (which are always the same
within every city. ie if the first city has departments 'A', 'B' and 'C'
every city will contain three department nodes)
   I create the unique list with
select="//department[not(@type=following::department/@type)]/@type"
* I then for-each over the unique list and match province nodes
* I then create a unique list of departments again, for each and match
area nodes etc.

One thing I am not sure of is how to reference the node matched by the
template while inside a for-each element.
<xsl:template match="province">
	<xsl:for-each select="department">
		...if I want to reference an area as a child of the matched province
from here, what do I do?...
	</xsl:for-each>
</xsl:template>

I hope that I have explained enough for some help.
Thank you for your time and effort in helping.

Andrew




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.