xsl-list
[Top] [All Lists]

Re: [xsl] Finding distinct nodes using a function in XSLT 2.0

2007-04-18 05:51:44
Dimitre Novatchev wrote:
On 4/17/07, Scott Lynch <slynch(_at_)nortel(_dot_)com> wrote:
Dimitre,

That works nicely.

However, is there any difference between
<xsl:sequence select="."/>
(which works) rather than say
<xsl:sequence select="current-group()[1]"/>
which also works, in the overall template logic?

Hi Scott,

No there isn't any difference (in this case), because as the XSLT2.0 spec says:



But note that (the other case) you can use current-group() still when the context item has changed. I.e., in another template which is called or indirectly invoked from your for-each-group. In which case the dot '.' will contain something else then current-group()[1]

Btw, you can also do the distinct nodes in a single xpath (the title of your post seems to suggest you were looking for a function), as long as your identity is based on a value (of @id):

   <xsl:variable name="files"
         select="document(('file1.xml', 'file2.xml'))" />
<xsl:template match="/" name="main">
       <xsl:copy-of select="
           for $i in distinct-values($files/*/*/@id)
           return ($files/*/*[(_at_)id = $i])[1]" />
   </xsl:template>


If you need sorting, you can use xsl:perform-sort, change the xsl:copy-of like this:

  <!-- or, with sorting -->
  <xsl:perform-sort select="
        for $i in distinct-values($files/*/bar/@id)
        return ($files/*/*[(_at_)id = $i])[1]" >

      <xsl:sort select="@id" />
  </xsl:perform-sort>


(btw: note the double parentheses around the fn:document() function, they are on purpose)

Cheers,
-- Abel Braaksma





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--