Gary McGill
Usenet Archive
- Joined
- Dec 3, 2004
- Messages
- 7
- Reaction score
- 0
Suppose I have an xml file that looks like this:
<example>
<foo id="1">
<bar id="a1"/>
<bar id="b1"/>
...
</foo>
<foo id="2">
<bar id="a2"/>
<bar id="b2"/>
...
</foo>
...
</example>
In other words, there are multiple foo elements, each of which contains multiple bar elements.
Now suppose I want to produce a list of all the bar ids. I can do this with the following XPath expression:
/example/foo/bar/@id
This will give me:
a1
b1
...
a2
b2
...
etc.
Now for my question: how do I get a list of the foo ids that matches the list of bar ids? That is, rather than having each foo id listed once, I want it listed as many times as there are corresponding bars.
If I use an XPath expression similar to the one above:
/example/foo/@id
....then I just get each foo id listed once:
1
2
etc.
....whereas what I want is:
1
1
...
2
2
...
etc.
I want to do this so that when I display the lists side-by-side, they correspond, as in:
1 a1
1 b1
...
2 a2
2 b2
...
etc.
I tried using the following expression:
/example/foo/bar/../@id
....in the hope that referencing the bar element would mean that I got as many output nodes as there are bars, but that didn't work - it still only gave me one of each foo id.
Is there a way to do what I'm trying to do?
Thanks,
Gary
<example>
<foo id="1">
<bar id="a1"/>
<bar id="b1"/>
...
</foo>
<foo id="2">
<bar id="a2"/>
<bar id="b2"/>
...
</foo>
...
</example>
In other words, there are multiple foo elements, each of which contains multiple bar elements.
Now suppose I want to produce a list of all the bar ids. I can do this with the following XPath expression:
/example/foo/bar/@id
This will give me:
a1
b1
...
a2
b2
...
etc.
Now for my question: how do I get a list of the foo ids that matches the list of bar ids? That is, rather than having each foo id listed once, I want it listed as many times as there are corresponding bars.
If I use an XPath expression similar to the one above:
/example/foo/@id
....then I just get each foo id listed once:
1
2
etc.
....whereas what I want is:
1
1
...
2
2
...
etc.
I want to do this so that when I display the lists side-by-side, they correspond, as in:
1 a1
1 b1
...
2 a2
2 b2
...
etc.
I tried using the following expression:
/example/foo/bar/../@id
....in the hope that referencing the bar element would mean that I got as many output nodes as there are bars, but that didn't work - it still only gave me one of each foo id.
Is there a way to do what I'm trying to do?
Thanks,
Gary