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

RE: counting matches between list items

Subject: RE: counting matches between list items
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 20 Jun 2001 17:01:08 +0100
list item types
> I'm new to XSL, so this might be a simple question. I'm 
> trying to compare
> the items in two lists using XSL to check if an item at a 
> certain position
> in the two lists matches. For example, the lists below have 1 
> matching item.
> 
> <LISTS> 
> 	<LIST_A> 
> 		<ITEMS> 
> 			<ITEM type="dog" /> 
> 			<ITEM type="cat" /> 
> 			<ITEM type="fish" /> 
> 		</ITEMS> 
> 	</LIST_A> 
> 	<LIST_B> 
> 		<ITEMS> 
> 			<ITEM type="dog" /> 
> 			<ITEM type="fish" /> 
> 			<ITEM type="cat" /> 
> 		</ITEMS> 
> 	</LIST_B> 
> </LISTS>

There may be a more direct solution, but you could try

<xsl:variable name="listB" select="LISTS/LIST_B/ITEMS"
<xsl:variable name="matches">
  <xsl:for-each select="LISTS/LIST_A/ITEMS/ITEM">
    <xsl:variable name="pos" select="position()"/>
    <xsl:if test="@type = $listB/ITEM[$pos]/@type">Z</xsl:if>
  </xsl:for-each>
</xsl:variable>
<xsl:value-of select="string-length($matches)"/>

Mike Kay
Software AG
 
> I've tried using count() <xsl:variable name="listMatches"
> select="count(LISTS/LIST_A/ITEMS[normalize-space(./attribute::
> type)=LISTS/LI
> ST_B/ITEMS/attribute::type])"/> But count() does not take the 
> position of
> the elements into account. I can't figure out how to 
> accumulate a count
> using <xsl:for-each>. If anyone has any suggestions, please 
> let me know. 
> Thanks, 
> - Matthew 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 

 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-2013 All Rights Reserved.