|
Subject: Re: [xsl] current context preceding-sibling then following-sibling From: Karl Stubsjoen <kstubs@xxxxxxxxx> Date: Tue, 8 Mar 2005 13:58:03 -0700 |
I've tested the above preceding-sibling following-sibling scenarios
and they work as described, thanks J.Petschmann.
I have included a simpler example as to what data I am after. Here is
the XML source followed by the intent of the xpath query to build
followed by the xpath query that I have written so far:
<data>
<code>
<record id="40" says="ruff" animal="dog">
<field fieldname="chase" id="50">cat</field>
</record>
<record id="50" says="meow" animal="cat">
<field fieldname="chase" id="60">mouse</field>
</record>
<record id="60" says="squeak" animal="mouse">
<field fieldname="chase" id="00">cheese</field>
</record>
</code>
<animals>
<animal id="60" />
<animal id="50" />
<animal id="40" />
<animal id="50" />
<animal id="60" />
<animal id="40" />
<animal id="50" />
<animal id="40" />
<animal id="80" />
</animals>
</data>
I am interested in returning all matches for animals who are in a
proper "chase" order. So for example, the above animal who's ID is
50, is correctly in order if the proceding-animal is 40 (there should
be 2 matches). Similarily, the animal who's ID is 60 is in correct
order one time with the proceding-animal who's ID is 50. This "chase"
order is to be derived by the code/record lookup above.
Here is what I have sofar for xpath queries:
HARD CODED SOLUTION:
/data/animals/animal[preceding-sibling::animal[1][@id = ( '40' ) and
following-sibling::animal[1]/@id= ( '50' ) ]]
FIRST 40 WOULD BE SUBSTITUTED WITH:
/data/code/record[field[@id=( '50' )]]/@id
RESULT OF THIS SUBSTITUTION:
/data/animals/animal[preceding-sibling::animal[1][@id = (
/data/code/record[field[@id=( '50' )]]/@id ) and
following-sibling::animal[1]/@id= ( '50' ) ]]
The above hard coded xpath query works...
My dilemna: I can not hard code the 50. I need to return all chase /
chasee combinations.
Any ideas?
On Mon, 07 Mar 2005 20:47:38 +0100, J.Pietschmann <j3322ptm@xxxxxxxx> wrote:
> Karl Stubsjoen wrote:
> > the context of the following-sibling following a preceding-sibling
> > should result you in the context of the current sibling?
>
> It depends. Note:
>
> > The short of it is, I am comparing the preceding-sibling with the
> > current. The preceding-sibling must contain the code "XYZ" when the
> > current contains the code "WXY".
>
> If you talk about "content", be aware that looking up elements
> both in the preceding-sibling and the following-sibling axis
> are likely to produce node sets, and the stringification of a
> node set will result in the string value of the first element in
> document order. An example XML
> <foo>
> <bar>1</bar>
> <bar>2</bar>
> <bar id="3">3</bar>
> </foo>
> The statement
> <xsl:value-of select="
> /foo/bar[@id='3']/preceding-sibling::bar
> /following-sibling::bar"/>
>
> Will get you a 2, not a 3 as you might expect.
> If in doubt, use a position predicate
> <xsl:value-of select="
> /foo/bar[@id='3']/preceding-sibling::bar[1]
> /following-sibling::bar[1]"/>
>
> J.Pietschmann
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] current context preceding, J.Pietschmann | Thread | Re: [xsl] current context preceding, Joris Gillis |
| Re: [xsl] Is there a reason for not, Elliotte Harold | Date | RE: [xsl] Is there a reason for not, Michael Kay |
| Month |