|
Subject: Re: [xsl] XPath: selecting matching nodes in two node-sets From: Mukul Gandhi <mukulgw3@xxxxxxxxx> Date: Mon, 20 Oct 2003 05:12:48 -0700 (PDT) |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XPath: selecting matching, andrew . curry | Thread | RE: [xsl] XPath: selecting matching, Michael Kay |
| Re: [xsl] XPath: selecting matching, Dimitre Novatchev | Date | [xsl] xsl doesnt produce valid xhtm, james walker |
| Month |