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(_dot_)lewis(_at_)uea(_dot_)ac(_dot_)uk> 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