1

Hi, I need to group values twice based on some attribute and populate it.

below the xml and I want a group-by on UITVOERINGSNIVEAU and Enveloppe

<rows>
  <row Enveloppe="ACOS" POST_NUM="1000" UITVOERINGSNIVEAU="BnComd" CSTAMNUMMER="1" /> 
  <row Enveloppe="ACOS" POST_NUM="5000" UITVOERINGSNIVEAU="BnComd" CSTAMNUMMER="2" /> 
  <row Enveloppe="DG" POST_NUM="1001" UITVOERINGSNIVEAU="BdeComd" CSTAMNUMMER="4" /> 
</rows>

I want the result as below:

<rows> 
      <row> 
        <cell image="folder.gif">BnComd</cell> 
        <row>
           <cell image="folder.gif">ACOS</cell> 
              <row> 
                 <cell>1000</cell> 
                 <cell>1</cell>
              </row>
              <row>
                 <cell>5000</cell> 
                 <cell>2</cell>
              <row>
        </row>  
     </row>
     <row> 
        <cell image="folder.gif">BdeComd</cell> 
          <row> 
            <cell image="folder.gif">DG</cell>
              <row> 
                 <cell>1001</cell> 
                 <cell>4</cell>
              </row>
        </row>
      </row> 
    </rows>

I Find this to do a group-by on only UITVOERINGSNIVEAU, but I don't know how to integrate my second group-by:

<xsl:template match="/*">
  <rows>
    <xsl:for-each-group select="//rows/row" group-by="@UITVOERINGSNIVEAU">
      <row>
        <cell image="folder.gif"><xsl:value-of select="current-grouping-key()"/></cell>
        <xsl:apply-templates select="current-group()"/>
      </row>
    </xsl:for-each-group>
  </rows>
</xsl:template>

<xsl:template match="row">
  <row>
    <xsl:apply-templates select="@* except @UITVOERINGSNIVEAU"/>
  </row>
</xsl:template>

<xsl:template match="row/@*">
  <cell><xsl:value-of select="."/></cell>
</xsl:template>

can someone help me please?

thanks

4

1 回答 1

1

If you want to group the second time it is possible to do it like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/*">
        <rows>
            <xsl:for-each-group select="//rows/row" group-by="@UITVOERINGSNIVEAU">
                <row>
                    <cell image="folder.gif">
                        <xsl:value-of select="current-grouping-key()"/>
                    </cell>
                    <xsl:for-each-group select="current-group()" group-by="@Enveloppe">
                        <row>
                            <cell image="folder.gif">
                                <xsl:value-of select="current-grouping-key()"/>
                            </cell>
                            <xsl:apply-templates select="current-group()"/>
                        </row>
                    </xsl:for-each-group>
                </row>
            </xsl:for-each-group>
        </rows>
    </xsl:template>

    <xsl:template match="row">
        <row>
            <xsl:apply-templates select="@* except (@UITVOERINGSNIVEAU | @Enveloppe)"/>
        </row>
    </xsl:template>

    <xsl:template match="row/@*">
        <cell>
            <xsl:value-of select="."/>
        </cell>
    </xsl:template>
</xsl:stylesheet>
于 2013-11-14T14:15:50.303 回答