xsl-list
[Top] [All Lists]

RE: Urgent: Grouping attributes together

2003-06-17 23:55:39
On Wed, 18 Jun 2003 Jarno(_dot_)Elovirta(_at_)nokia(_dot_)com wrote:

FFFAQ,

I need help to write an XSLT file for converting first.xml to
second.xml
where the attribute values are grouped

Did you have a look at the FAQ or Jeni's pages on grouping?

  <xsl:key name="class" match="student" use="@class"/>
  <xsl:template match="school">
    <xsl:copy>
      <xsl:for-each select="student[generate-id(.) = generate-id(key('class', 
@class))]">

I would replace this:
        <Section class="A">

to  <Section class="{(_at_)class}">

          <xsl:apply-templates select="key('class', @class)"/>
        </Section>
      </xsl:for-each>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="student/@class"/>
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>


Result:
<?xml version="1.0"?>
<school>
  <Section class="A">
    <student>L</student>
    <student>O</student>
    <student>S</student>
  </Section>
  <Section class="B">
    <student>M</student>
    <student>Q</student>
  </Section>
  <Section class="C">
    <student>P</student>
    <student>R</student>
  </Section>
</school>

Cheers,
Jarkko

****************************************************************
Jarkko Moilanen          "Erehtyminen on inhimillista,
Researcher                mutta todella suuret mokat
jm60697(_at_)uta(_dot_)fi            vaativat tietokoneen käyttöä."
www.uta.fi/~jm60697
GSM: +358 50 3766 927
****************************************************************
* ITCM | Information Technology and Crisis Management
* http://www.itcm.org
****************************************************************






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



<Prev in Thread] Current Thread [Next in Thread>