RE: [xsl] Common Element Solution (XSL 2.0)

Subject: RE: [xsl] Common Element Solution (XSL 2.0)
From: "Pawson, David" <David.Pawson@xxxxxxxxxxx>
Date: Wed, 23 Mar 2005 10:23:36 -0000
    -----Original Message-----
    From: Michael Kay

    > My question was, how does the '/' eliminate duplicates?
    > That's the bit I don't understand.

    If the input is

    >    <table name="table1">
    >      <column name="col1"/>
    >      <column name="col2"/>
    >      <column name="col3"/>
    >      <column name="col4"/>
    >    </table>
    >    <table name="table2">
    >      <column name="col1"/>
    >      <column name="col2"/>
    >      <column name="col5"/>
    >      <column name="col5"/>
    >    </table>

    then when processing col5, count(current-group()) will be 2, but
    count(current-group()/parent::table) will be 1, because
    both columns in the group have the same parent element.


Thanks Mike. Now I see it.
xslt 2.0 stylesheet below demonstrates it.

regards DaveP

  <xsl:variable name="table-count" select="count(/tables/table)"/>

 <xsl:template match="tables">
    <xsl:for-each-group select="table/column" group-by="@name">
    <xsl:if test="count(current-group())=$table-count">
        <columnName><xsl:value-of
select="current-grouping-key()"/></columnName>
    </xsl:if>


      <p><i>count(current-group())<xsl:value-of
                 select="count(current-group()) "/></i></p>
      <p><i>count(current-group())/parent::table <xsl:value-of
                 select="count(current-group()/parent::table) "/></i></p>
  </xsl:for-each-group>

  </xsl:template>

Current Thread