|
Subject: Re: [xsl] XSLT: XPath: Siblings From: Francis Norton <francis@xxxxxxxxxxx> Date: Wed, 28 Feb 2001 10:34:54 +0000 |
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] XSLT: XPath: Siblings, Lee Goddard | Thread | [xsl] Re: X3D issues for XSLT, from, Don Brutzman |
| Re: [xsl] XSLT: XPath: Siblings, Lee Goddard | Date | RE: [xsl] Using XSL and schemas to , Chris Kilner |
| Month |