xsl-list
[Top] [All Lists]

RE: unique attribute values in XSLT2 - storing them in a variable

2005-02-22 04:09:37
You just need

<xsl:variable name="x" select="distinct-values(/A/B/C/@atc)"/>

Your construct

<xsl:for-each-group select="B/C" group-by=".">

is unnecessary and achieves nothing: the C elements are all empty, so they
all have the same grouping key, so they all go in a single group.

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: jozef(_dot_)aerts(_at_)xml4pharma(_dot_)com 
[mailto:jozef(_dot_)aerts(_at_)xml4pharma(_dot_)com] 
Sent: 22 February 2005 10:52
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] unique attribute values in XSLT2 - storing 
them in a variable


Dear all,

I am making the transition now from XSLT1 to XSLT2

I have the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<A at1="1" at2="2">
      <B atb="3">
              <C atc="a"/>
              <C atc="b"/>
      </B>
      <B atb="3">
              <C atc="a"/>
              <C atc="c"/>
      </B>
</A>

I need to find all unique values of the @atc attribute, and store them
in a variable for later use.
That was no problem in XSLT1, but I still have some problems in XSLT2.

This is what I have:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">
      <xsl:template match="/">
              <xsl:apply-templates select="A"/>
      </xsl:template>
      
      <xsl:template match="A">
      <xsl:for-each-group select="B/C"
                      group-by=".">
              <xsl:sort select="." />
              <xsl:value-of select="." />
              <xsl:for-each 
select="distinct-values(current-group()/@atc)">
                              distinct @atc = <xsl:value-of 
select="." />
              </xsl:for-each>
      </xsl:for-each-group>
      </xsl:template>
</xsl:stylesheet>

This indeed gives:
distinct @atc = a
distinct @atc = b
distinct @atc = c

But how do I store these values in a variable for later use ?

Many thanks in advance

Jozef

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





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



<Prev in Thread] Current Thread [Next in Thread>