[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: key match and x-path problems

Subject: RE: key match and x-path problems
From: "Kevin Jones" <kjjones@xxxxxxxxxxxx>
Date: Tue, 23 Apr 2002 14:34:21 +0100
x path global search
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.