Re: [xsl] weird key-nodeset behavior

Subject: Re: [xsl] weird key-nodeset behavior
From: Osman Çınar Eren <Cinar.Eren@xxxxxxxxxxxxx>
Date: Fri, 26 Nov 2004 09:01:59 +0200
Hi David,

thank you for your answer. What i understand from your answer is we cannot use
<xsl:key> s over nodesets.
what i try to do is as follows:
i have such elements:
<value>
	<A>1</A>
	<dovizler>
		<key>USD</key>
		<value>
			<B>100</B>
		</value>
	</dovizler>
	<dovizler>
		<key>EUR</key>
		<value>
			<B>400</B>
		</value>
	</dovizler>
</value>

Firstly i group the document which is composed of these elements according to
their 'A' values, which is straightforward:
<xsl:key name="categorise" match="value" use="A"/>
<xsl:for-each select="value[generate-id()=
generate-id(key('categorise',A)[1])]">
<xsl:variable name="muhID"><xsl:value-of select="A" /></xsl:variable>
<xsl:variable name="muhkodlar" select="//value[A=$muhID]" />

So i have the nodeset '$muhkodlar'.
Then i want to list the distinct 'dovizler' values of this nodeset. and write
down the sum of the dovizler elements whose 'key' values are same:
<xsl:key name="dkey" match="dovizler" use="key"/>

<xsl:for-each select="$mydovizler//dovizler[generate-id(.) =
generate-id(key('dkey',key)[1])]">

<xsl:variable name="dovID"><xsl:value-of select="key" /></xsl:variable>
<xsl:variable name="dovGrp" select="$mydovizler//dovizler[key=$dovID]" />
     	<xsl:call-template name="dovizTop">
      		<xsl:with-param name="dovGrp" select="$dovGrp" />
      		<xsl:with-param name="dovID" select="$dovID" />
     	</xsl:call-template>

</xsl:for-each>

<xsl:template name="dovizTop">
<xsl:param name="dovGrp" />
<xsl:param name="dovID" />
<!--<xsl:for-each select="$dovGrp">-->
<fo:table-row>
        <fo:table-cell>
		<fo:block text-align="right" font-size="8pt" >
		<xsl:value-of select="$dovID"/>-
		</fo:block>
	</fo:table-cell>
	<fo:table-cell>
		<fo:block text-align="left" font-size="8pt" >
		<xsl:value-of select="sum($dovGrp/value/B)"/>
		</fo:block>
	</fo:table-cell>
        </fo:table-row>
<!--</xsl:for-each>-->
</xsl:template>

I should see:
USD 500
EUR 1000
...
where the values next to the keys are the sum of all B values for that
key(e.g. USD) on that nodeset(muhkodlar).

Could i tell what i want?
I will appreciate if you can help.
regards..

-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Thursday, November 25, 2004 6:04 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] weird key-nodeset behavior
detected spam



> 3) the key definition does not work for the nodeset.

They key indexes all elements in the document: it has nothing to so with
any variable.

If you have
<xsl:key name="key" match="dovizler" use="key">

and <xsl:variable name="mydovizler" select="dovizler[2]"/>

Then given
<x>
<dovizler><key>a</key></dovizler>
<dovizler><key>a</key></dovizler>
</x>

Your expression of

select="$mydovizler[generate-id(.) =  generate-id(key('dkey',key)[1])]"

will work, but it will select all the elements in $mydovizler that are
the first elements in the document for their key value.

In this case there is only one element in mydovizler, and it has key
value 'a' but it isn't the first such element in the document so
the empty node set is selected.

the key definition works, it just isn't doing what you want.

Unfortunately it isn't clear what you do want as you only showed the non
working definition, not a description of what you are trying to do.

> should i give the input file?(xml and xsl)

complete runnable files are good, but best to take the time to cut them
down as above to five or six lines, so that just the problem is
highlighted not your entire input source.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread