|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT: XPath: Siblings
Lee Goddard wrote:
>
> My understanding of this has to be wrong:
>
It is :)
> <xsl:apply-templates/>
>
> <xsl:template match="/*/*">
> | <xsl:value-of select="name()"/>
> ---
> <xsl:value-of select="preceding-sibling::*[name()]"/> |
> </xsl:template>
>
> Shouldn't the second clause above output the value
> of the name of the preceding sibling? It seems to be
> outputting the text content of the first element on
> the page. I can't understand why?
>
Because the stuff inside the square bracket is a predicate, like an SQL
where clause. That's why you're getting content rather than name.
The reason you're getting the first one is, I suspect, that although the
preceding-sibling axis is ordered <em>as far as predicates on it are
concerned</em>. Once you've applied an accidental predicate which
selects every element on the axis (because every element has a name,
which got converted to a boolean true) the result of the expression is a
good old-fashioned un-ordered node-set. xsl:value-of converts its select
argument to a string as if by string(), and the XPath spec says:
"The string function converts an object to a string as follows:
A node-set is converted to a string by returning the
string-value of the node in the node-set that is first in document
order. If the node-set is empty, an empty string is returned."
In other words, you want something like
<xsl:value-of select="name(preceding-sibling::*[1])"/>
> All I ever do is ask questions here... many thanks for
> all the help I get; I can repay you on the Perl lists
> at activestate.com....
>
No problem :)
Francis.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








