如何在XSLT中使用group-by忽略空格?

时间:2011-12-08 18:32:21

标签: xslt xslt-2.0 xslt-grouping

我有一个xml文件,我需要使用xsl:for-each-group进行分组。一切正常,但问题来自于有些元素在其末尾有空白区域(例如<word>test </word> and <word>test</word>),但我需要将它们视为一组。

以下是示例xml文件:

<u>
  <s>
    <w>this </w>
    <w>is </w>
    <w>a </w>
    <w>test </w>
  </s>
  <s>
    <w>this</w>
    <w>is</w>
    <w>a</w>
    <w>test</w>
  </s>
<u>

这是xslt代码

<xsl:for-each-group select="bncDoc/stext/div/u/s" group-by="w" >
  <tr>  
    <td style="text-align: center;">
      <xsl:value-of select="current-grouping-key()"/>
    </td>
    <td>
      <xsl:value-of select="count(current-group())"/>
    </td>
  </tr>
</xsl:for-each-group>

有没有解决方法呢?

2 个答案:

答案 0 :(得分:3)

<xsl:for-each-group select="bncDoc/stext/div/u/s/w" group-by="normalize-space()">
   <!-- ... -->
</xsl:for-each-group>

答案 1 :(得分:1)

好的,找到了答案:

您只需要以这种方式使用normalize-space():

    <xsl:for-each-group select="bncDoc/stext/div/u/s/w" group-by="normalize-space((text())">
        .
        .
        .
    </xsl:for-each-group>
相关问题