RE: [xsl] key match and x-path problems

Subject: RE: [xsl] key match and x-path problems
From: "Kevin Jones" <kjjones@xxxxxxxxxxxx>
Date: Tue, 23 Apr 2002 14:34:21 +0100
> So how could I then count the correct number of unique statuses ?
>
> Ahmad
>
>

Here is a solution which I think does what you want, i.e. count the number
of times a CHARACTER_STATUS value is used in the DIRECT, LOCAL, GLOBAL,
ADMIN elements that are the first to contain any CHARACTER_ID.

The easy way is probably using a second key to map CHARACTER_STATUS values
to the parent element.

<xsl:key name='kByStatus' match="DIRECT | LOCAL | GLOBAL | ADMIN"
use="number(CHARACTER_STATUS)"/>

You can the use,

<xsl:for-each select="$vUniqueCharacters">
	<xsl:variable name='sameStatus'
select="key('kByStatus',number(CHARACTER_STATUS))"/>
	<xsl:variable name='intersect'
select='$vUniqueCharacters[count(.|$sameStatus)=count($sameStatus)]'/>

	<xsl:if test=".=$intersect[1]">
		<xsl:text>STATUS </xsl:text>
		<xsl:value-of select='CHARACTER_STATUS'/>
		<xsl:text>SUM </xsl:text>
		<xsl:value-of select="count($intersect)"/>
		<xsl:value-of select="$NL"/>
	</xsl:if>
</xsl:for-each>

The loop iterates over the unique characters. To find if this is first with
a given CHARACTER_STATUS it computes the intersect of the unique characters
and all the ones which have the same CHARACTER_STATUS value. For there on
its fairly straight forward to determine if this is first one in that set
and how many others are in the set.

Kev.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread