-1

我需要根据某些属性对值进行分组并填充它。

在 xml 下面,我想按 UITVOERINGSNIVEAU 分组

    <?xml version="1.0" encoding="UTF-8" ?> 
 <dbqueries>
  <environment>LOCAL</environment> 
  <label /> 
  <description /> 
 <dbquery id="lijst">
 <descriptor>
  <database /> 
  <originalquery>select * from T_L5_HRB_Lijst_Comd</originalquery> 
  <querystring>select * from T_L5_HRB_Lijst_Comd</querystring> 
  </descriptor>
 <columns>
  <column name="Enveloppe" type="VARCHAR" /> 
  <column name="ORG_NUM" type="VARCHAR" />
  <column name="UITVOERINGSNIVEAU" type="VARCHAR" /> 
  <column name="CSTAMNUMMER" type="VARCHAR" />  
  </columns>
 <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>

因此,对于每个 UITVOERINGSNIVEAU,我想获得一个带有标题的单元格,然后在上面的每一行中获得一个带有该 UITVOERINGSNIVEAU 的行。对于我写的示例,它必须如下所示:

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

1 回答 1

1

利用

<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>
于 2013-11-12T11:18:43.753 回答