This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
XML Reorganisation
- From: Andrew Timberlake <andrew dot lists at ddd dot co dot za>
- To: XSL List <xsl-list at lists dot mulberrytech dot com>
- Date: 22 May 2002 12:29:31 +0200
- Subject: [xsl] XML Reorganisation
- Reply-to: xsl-list at lists dot mulberrytech dot com
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