xsl-list
[Top] [All Lists]

RE: multi-level grouping on attributes

2005-10-06 05:02:02
If the grouping key for an item is an empty sequence, the item doesn't go in
any group. So you need to invent an artificial grouping key for such items.
For example

@group-by="(@absatz, -1)[1]"

will allocate a grouping key of -1 to einträge that have no absatz.

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: Klocker Christoph 
[mailto:Christoph(_dot_)Klocker(_at_)lexisnexis(_dot_)at] 
Sent: 06 October 2005 12:50
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] multi-level grouping on attributes

Hi
 
I try to achieve a multilevel grouping on attributes:
I got several items like these

<SI>
<eintrag pos="181" paragraph="3">aa</eintrag>
<eintrag pos="182" paragraph="3" absatz="1">aa</eintrag>
<eintrag pos="183" paragraph="3" absatz="1">bb</eintrag>
<eintrag pos="184" paragraph="3" absatz="2" a_litera="a" >aa</eintrag>
<eintrag pos="185" paragraph="3" absatz="2" a_litera="a"
ziffer="15">aa</eintrag>
<eintrag pos="186" paragraph="3" absatz="2" a_litera="a"
ziffer="15">bb</eintrag>
<eintrag pos="187" paragraph="3" absatz="2" ziffer="16">aa</eintrag>
<eintrag pos="188" paragraph="5" absatz="5">aa</eintrag>
<eintrag pos="189" paragraph="5" absatz="5" a_litera="a">aa</eintrag>
</SI>

Result should be:
<SI>
 <document>
    <eintrag pos="180" paragraph="3">aa</eintrag>
    <eintrag pos="181" paragraph="3">bb</eintrag>
 </document>
 <document>
   <eintrag pos="182" paragraph="3" absatz="1">aa</eintrag>
   <eintrag pos="183" paragraph="3" absatz="1">bb</eintrag>
 </document>
 <document>
    <eintrag pos="184" paragraph="3" absatz="2">aa</eintrag>
 </document>
<document>
    <eintrag pos="185" paragraph="3" absatz="2" a_litera="a"
ziffer="15">aa</eintrag>
    <eintrag pos="186" paragraph="3" absatz="2" a_litera="a"
ziffer="15">bb</eintrag>
</document>
</SI>

I started with:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xs="http://www.w3.org/2001/XMLSchema"; >
      <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="/">
<SI>
      <xsl:for-each-group select="//eintrag" group-by="@paragraph">
        <xsl:choose>
                              <xsl:when
test="current-group()/@absatz">
                                      <xsl:for-each-group
select="current-group()" group-by="@absatz">
                                              <document>
                                              <xsl:copy-of
select="current-group()" copy-namespaces="no"/>
                                      </document>
                                      </xsl:for-each-group>
                              </xsl:when>
                              <xsl:otherwise>
                                      <document>
                                              <xsl:copy-of
select="current-group()" copy-namespaces="no"/>
                                      </document>
                              </xsl:otherwise>
              </xsl:choose>           
      </xsl:for-each-group>
</SI> 
</xsl:template>
</xsl:stylesheet>

The problem is, I loose the <entry> which has no @absatz.
What is the right <xsl:choose> to achieve the required result.

Thx
Christoph





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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