xsl-list
[Top] [All Lists]

RE: [xsl] Preceding axis conumdrum

2006-08-25 15:52:59
Or,

preceding-sibling::row[cell[(_at_)columnHeader='ItemDate'][normalize-space()]][1]/
  cell[(_at_)columnHeader='ItemDate']

which first looks on the preceding sibling axis for rows with cells with @columnHeader='ItemDate' and text content (reducing the string-length test to a simple boolean coercion on the string), taking the first one, and then continues to that cell in a second step.

In this case the predicate [1] selects the first in reverse document order, since preceding-sibling:: is a "reverse axis". In the proposed path, the predicate [1] is working on the second step, "cell[...]", whose axis is the implicit child:: axis. Hence several nodes are being selected (each the first such child of its parent) and the string value (as Mike points out) retrieves the value of the first in document order, not the most recent.

Cheers,
Wendell

At 03:53 PM 8/25/2006, Mike wrote:
> The expression I am trying to use to select that value is:
>
> Preceding-sibling::row/cell[(_at_)columnHeader='ItemDate'][not(stri
ng-length(
> normalize-space(.))=0)][1]

Try

(preceding-sibling::row/cell[(_at_)columnHeader='ItemDate'][not(string-length(nor
malize-space(.))=0)])[last()]

or more concisely

(preceding-sibling::row/cell[(_at_)columnHeader='ItemDate'][normalize-space(.)])[
last()]

The predicate [1] only gives you the last in document order if it's applied
immediately to a reverse axis. You're applying it to the child axis, so what
you asked for is:

for all the preceding-sibling rows
  select the child cells
    that have a columnHeader of "ItemDate"
    that aren't empty
    and if there's more than one such child, select the first

That will potentially select one cell in each row, and if you use this in
xsl:value-of in XSLT 1.0 this will discard all but the first.

Michael Kay
http://www.saxonica.com/


>
> Maybe I'm misunderstanding the axis, but I really can't
> understand why this doesn't work. In this case I seem to get
> '7 May' rather than what I want '11 May'.  I'm using Saxon8.0
> to process this.  Have I found a bug?
>
>
>                                       <row rowNumber="2">
>                                               <cell
> columnHeader="ItemCost">0.341</cell>
>                                               <cell
> columnHeader="ItemDuration">40:02</cell>
>                                               <cell
> columnHeader="ItemDestination">National</cell>
>                                               <cell
> columnHeader="ItemNoDialled">01415871046</cell>
>                                               <cell
> columnHeader="ItemTime">18:50</cell>
>                                               <cell
> columnHeader="ItemDate">7 May</cell>
>                                       </row>
>                                       <row rowNumber="3">
>                                               <cell
> columnHeader="ItemCost">0.389</cell>
>                                               <cell
> columnHeader="ItemDuration">45:39</cell>
>                                               <cell
> columnHeader="ItemDestination">Local</cell>
>                                               <cell
> columnHeader="ItemNoDialled">01294272776</cell>
>                                               <cell
> columnHeader="ItemTime">19.31</cell>
>                                               <cell
> columnHeader="ItemDate">11 May</cell>
>                                       </row>
>                                       <row rowNumber="4">
>                                               <cell
> columnHeader="ItemCost">0.172</cell>
>                                               <cell
> columnHeader="ItemDuration">8:25</cell>
>                                               <cell
> columnHeader="ItemDestination">Local</cell>
>                                               <cell
> columnHeader="ItemNoDialled">01294217616</cell>
>                                               <cell
> columnHeader="ItemTime">08:54</cell>
>                                               <cell
> columnHeader="ItemDate"></cell>
>                                       </row>
>                                       <row rowNumber="5">
>                                               <cell
> columnHeader="ItemCost">0.237</cell>
>                                               <cell
> columnHeader="ItemDuration">3:42</cell>
>                                               <cell
> columnHeader="ItemDestination">National Rate Call</cell>
>                                               <cell
> columnHeader="ItemNoDialled">08706099000</cell>
>                                               <cell
> columnHeader="ItemTime">13:53</cell>
>                                               <cell
> columnHeader="ItemDate"/>
>                                       </row>
>
> Many thanks,
>    Ed
>
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
> --~--
>


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>