1

Topic: How to select nodes on several elements from other branch?

Prompt how to make the following thing, please:
There is a dial-up of persons and the filter for them:

<root>
<filter>
<person>
<name>
John
</name>
<surname>
Smith
</surname>
</person>
</filter>
<data>
<person>
<name>
John
</name>
<surname>
Lumber
</surname>
</person>
<person>
<name>
John
</name>
<surname>
Smith
</surname>
</person>
<person>
<name>
Bill
</name>
<surname>
Carpenter
</surname>
</person>
</data>
</root>

So we select at whom the name is in the filter:

/root/data/person [name =/root/filter/person/name]

And how to select at what the name is in the filter, and the surname differs?
I.e. the result should be:

<person>
<name>
John
</name>
<surname>
Lumber
</surname>
</person>

2

Re: How to select nodes on several elements from other branch?

The decision on XPath interests or approaches XSL?

3

Re: How to select nodes on several elements from other branch?

It is necessary XPATH, at what to version 1.0

4

Re: How to select nodes on several elements from other branch?

Though looking what to understand under XSLT
If it turns out in xsl:variable to push this node set, even by means of several instructions xslt such decision descends also

5

Re: How to select nodes on several elements from other branch?

wrote:

dies irae;
Well and write logical operator AND

Thanks for council, but try to investigate at first all into task setting

/root/data/person [name =/root/filter/person/name] [surname =/root/filter/person/surname]

It deduces all persons which name is in the filter and which surname is in the filter, without communication of one with another

6

Re: How to select nodes on several elements from other branch?

wrote:

dies irae;
Then only through logical operator AND

No

7

Re: How to select nodes on several elements from other branch?

wrote:

just checked up at me works only so

root/data/person [(name =./././root/filter/person/name) and (surname =./././root/filter/person/surname)]

No, not that
I resulted result which should turn out.
And a condition: to select at what the name is in the filter, and the surname differs
I.e. for each person it is passable on persons from the filter. If the name identical, and a surname different - a node approaches.
And at you produces all at which the name enters into the filter and the surname enters into the filter

8

Re: How to select nodes on several elements from other branch?

wrote:

well so select only by name

I would select only by name, but it is necessary for me on a surname

9

Re: How to select nodes on several elements from other branch?

;
You still do not understand

wrote:

for each person it is passable on persons from the filter. If the name identical, and a surname different - a node approaches.

On such data

<root>
<filter>
<person>
<name>
John
</name>
<surname>
Smith
</surname>
</person>
<person>
<name>
Bill
</name>
<surname>
Lamber
</surname>
</person>
</filter>
<data>
<person>
<name>
John
</name>
<surname>
Lamber
</surname>
</person>
<person>
<name>
Bill
</name>
<surname>
Lamber
</surname>
</person>
</data>
</root>

Should produce:

<person>
<name>
John
</name>
<surname>
Lamber
</surname>
</person>

10

Re: How to select nodes on several elements from other branch?

wrote:

dies irae;
The strange filter for me, one expression will be not not mastered by me on the first version....

Here and I fight of half-day
Made while a cycle in xslt
The pancake, in sql it elementarily becomes

select *
from person
where not exists (
select *
from filter
where person.name = filter.name
and person.surname! = filter.surname
)

11

Re: How to select nodes on several elements from other branch?

wrote:

too most and in xpath

root/data/person [name = ancestor:: root/filter/person/name and surname! = ancestor:: root/filter/person/surname]

No. Analog in sql that you wrote:

select *
from person
where name in (select name from filter)
and surname not in (select surname from filter)

12

Re: How to select nodes on several elements from other branch?

wrote:

dies irae;
On what you try to solve this task? ? Or what another?

On XSLT I try. Actually, I solved it, a cycle, above wrote. But it would be more beautiful through pure xpath

wrote:

try here this expression...

No, this same

13

Re: How to select nodes on several elements from other branch?

;
All your attempts do not consider a condition

dies irae wrote:

it deduces all persons which name is in the filter and which surname is in the filter, without communication of one with another

dies irae wrote:

on XSLT I try

Well then all simply

<xsl:template match = "person">
<xsl:if test = "/root/filter/person [name = current ()/name and surname! = current ()/surname]">
<xsl:apply-templates select = "." mode = "process"/>
</xsl:if>
</xsl:template>

14

Re: How to select nodes on several elements from other branch?

[quote = _ Vasilisk _] it is passed...
Well then all is simple

On xslt I approximately as made
It is interesting, whether it is possible on xpath to unscrew