Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Grouping sets of tags with XSLT

From: masonmarc@-----.---
To: NULL
Date: 9/2/2005 4:09:00 AM
I have a document like:

<all>
  <phone>
    <number>12345</number>
    <r comp="1"/>
    <r comp="2"/>
    <r comp="3"/>
    <r comp="1">
      <r address="a"/>
    </r>
    <r comp="2">
      <r address="b"/>
    </r>
    <r comp="3">
      <r address="c"/>
    </r>
    <r comp="1">
      <r country="a1"/>
    </r>
    <r comp="2">
      <r country="b1"/>
    </r>
    <r comp="3">
      <r country="c1"/>
    </r>
  </phone>
  <phone>
    <number>67890</phone>
    <r comp="1"/>
    <r comp="1">
      <r address="a"/>
    </r>
    <r comp="1">
      <r country="a1"/>
    </r>
  </phone>
</all>

That I would like to use XSLT to transform to:

<all>
  <phone>
    <number>12345</number>
    <r comp="1">
      <r address="a"/>
      <r country="a1"/>
    </r>
    <r comp="2">
      <r address="b"/>
      <r country="b1"/>
    </r>
    <r comp="3">
      <r address="c"/>
      <r country="c1"/>
    </r>
  </phone>
  <phone>
    <number>67890</phone>
    <r comp="1">
      <r address="a"/>
      <r country="a1"/>
    </r>
  </phone>
</all>

So I need to do grouping.  I've used the key and generate-id trick to
do:

<xsl:key name="rs" match="r" use="@comp">

then:

<xsl:for-each select="r[generate-id(.)=generate-id(key('rs',
@comp)[1])]">

to select the r elements and then process them to get the correct
output.  Using this method I can get the first phone element to output
correctly, but when it gets to the second one (or any other one that
has an r element with a comp attribute that has already been processed,
the select in the for-each statement doesn't select anything (comp="1"
was already processed in the previous phone element), so I get no
output.  Does anyone have any ideas on how to get this to work or
another way to do it?

Thanks.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent