This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

XML Reorganisation


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]