1

I have an xml file which I need to group-by using xsl:for-each-group. Everything works fine but the problem comes from when there is elements which have white space at the end of them (e.g. <word>test </word> and <word>test</word>) but I need these to be considered as one group.

Here's the sample xml file:

<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>

Here's the xslt code

<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>

Is there any workaround for this?

Tomalak
  • 332,285
  • 67
  • 532
  • 628
Peymankh
  • 1,976
  • 25
  • 30
  • It would be helpful if you posted an example of the output that you are trying to produce. It is not clear whether you need to adjust your select statement or the group-by (or both). – Mads Hansen Dec 08 '11 at 19:19
  • I just need to adjust the group-by statement. – Peymankh Dec 08 '11 at 21:26

2 Answers2

3
<xsl:for-each-group select="bncDoc/stext/div/u/s/w" group-by="normalize-space()">
   <!-- ... -->
</xsl:for-each-group>
Tomalak
  • 332,285
  • 67
  • 532
  • 628
1

OK, found the answer:

You just need to use the normailize-space() in this way:

    <xsl:for-each-group select="bncDoc/stext/div/u/s/w" group-by="normalize-space((text())">
        .
        .
        .
    </xsl:for-each-group>
Peymankh
  • 1,976
  • 25
  • 30