[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] using position() inside Muenchian groups?


Subject: Re: [xsl] using position() inside Muenchian groups?
From: Eric Scheid <eric.scheid@xxxxxxxxxxxxxxx>
Date: Tue, 14 Oct 2008 14:07:33 +1100

On 14/10/08 1:18 PM, "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:

>> I'm thinking I could use Muenchian grouping to pull out all the PRDC
>> sub-fields for a record (and then all the DRCT, WRTR, etc), and I also know
>> how to use position() to access the corresponding sibling...
> 
> Actually, that isn't quite precise.  That isn't what position()
> returns.  The function returns the current position within the set of
> nodes in the scope of the instruction that used select=.

Fair enough, although in my case I know the FMPXMLRESULT doesn't contain any
text nodes between elements but even if it did then nth position within one
<COL/> set would line up with the nth position within the other <COL/> set
I'm interested in.

> So I think your question cannot be answered without seeing more
> details of your code.

I'm only at the stage of cargo culting at the moment :-( I estimate it would
take about 2 hours of fumbling in the dark to figure out just the Muenchian
grouping code, which could all be for naught if it turns out that position()
within the for-each for the keyed group is relative to the subset and not
the original set.

To clarify, say I have this XML

        <COL>
            <DATA>PRDC</DATA>
            <DATA>xxxx</DATA>
            <DATA>xxxx</DATA>
            <DATA>xxxx</DATA>
            <DATA>xxxx</DATA>
            <DATA>PRDC</DATA>
            <DATA>xxxx</DATA>
        </COL>

and whatever code is necessary to create a virtual selection that looks like

        <COL>
            <DATA>PRDC</DATA>
            <DATA>PRDC</DATA>
        </COL>

which I then use xsl:for-each to iterate over, would position() inside that
xsl:for-each give me 1,2 or 1,6?

I suspect the former, which means that this code:

 <xsl:variable name="p" select="position()"/>
 <xsl:value-of select="ancestor::fmp:ROW/fmp:COL[$crew_name]/fmp:DATA[$p]"/>

would output

    Alan Jones
    Big Cheese

from this source XML
        <COL>
            <DATA>Alan Jones</DATA>
            <DATA>Big Cheese</DATA>
            <DATA>Bill Smith</DATA>
            <DATA>Camera Guy</DATA>
            <DATA>Little Cheese</DATA>
            <DATA>Zachary Azimuth</DATA>
            <DATA>Dicky Dickens</DATA>
        </COL>

which is wrong for me because I wanted

    Alan Jones
    Zachary Azimuth

> So I think your question cannot be answered without seeing more
> details of your code.

I'm working on it :-) Hard to write code like this though because I don't
know if the wrong answers I'm getting is because I got a bug in my code, or
because it is simply impossible.

e.


Current Thread
Keywords
xml