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

Re: XPath: selecting matching nodes in two node-sets

Subject: Re: XPath: selecting matching nodes in two node-sets
From: Mukul Gandhi <mukulgw3@xxxxxxxxx>
Date: Mon, 20 Oct 2003 05:12:48 -0700 (PDT)
xpath selecting position
Hi Richard,
 From what I understood from the problem description,
I constructed the following XML --

<?xml version="1.0" encoding="UTF-8"?>
<results>
   <keywords>
     <matches>1</matches>
     <matches>2</matches>
     <matches>3</matches>
   </keywords>
   <item>
     <matches>1</matches>
     <matches>2</matches>
   </item>
   <item>
    <matches>1</matches>
    <matches>2</matches>
    <matches>3</matches>
   </item>
   <item>
     <matches>1</matches>
     <matches>2</matches>
   </item>
   <item>
     <matches>1</matches>
     <matches>2</matches>
     <matches>3</matches>	              
   </item>
   <item>
     <matches>1</matches>
     <matches>2</matches>
     <matches>3</matches>
     <matches>4</matches>
   </item>
</results>

(I have taken the above XML, as a test case. The
contents of the XML may vary(depending what is wanted,
for the real problem); but I have tried to make the
XML, identical according to the problem description,
given by you.)

The following XSL *tries to demonstrate*, how to
compare the <item> nodes following the <keywords>
node, with the *children of <keywords> node*) --

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
	
<xsl:template match="/results">
     <xsl:variable name="key-words">
       <xsl:copy-of select="keywords/matches" />
     </xsl:variable>
	      
     <xsl:for-each select="item">
        <xsl:variable name="item">
           <xsl:copy-of select="matches" />
        </xsl:variable>
	          
        <xsl:if test="$key-words = $item">
           Position of Item node (which is identical
to 'keywords' node) <xsl:value-of select="position()"
/>
        </xsl:if>	          
     </xsl:for-each>
</xsl:template>
	
</xsl:stylesheet>

After the desired comparison is performed, the
position of <item> node is printed, to get the
answer..

Hope, the above explanation is useful..

Regards,
Mukul

--- Richard Lewis <richard.lewis@xxxxxxxxx> wrote:
> I have the following document:
> 
> <results>
> 	<keywords>
> 		<matches>...</matches>
> 		...
> 	</keywords>
> 	<item>
> 		...various elements...
> 		<matches>...</matches>
> 		<matches>...</matches>
> 		...
> 	</item>
> 	<item>....</item>
> 	...
> </results>
> 
> (where <matches> elements contain the keywords
> themselves, CDATA).
> 
> and what I need is an XPath expression which selects
> all the <item>s which 
> have the same set of <matches /> elements as in the
> <keywords> node.
> (Note: there may be repetition of <matches />s in
> <item>s but not in 
> <keywords>)
> 
> I've tried:
> "//item[matches = //keywords/matches]"
> but this selects <item>s where not all the
> '//keywords/matches' elements are 
> present.
> 
> Cheers,
> Richard
> 
>  XSL-List info and archive: 
> http://www.mulberrytech.com/xsl/xsl-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

 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.