xsl-list
[Top] [All Lists]

RE: Conditional extraction of data

2004-11-08 07:53:27

-- 
Bryan Rasmussen

what I wrote earlier should solve that particular problem, text nodes have a
default template which is like this
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

this is why you don't actually have to use xsl:value-of to copy text, just
applying templates will copy without doing anything else unless you've
overridden the default template.
example overriding
<xsl:template match="text()"><xsl:text>I'm overriding the default text template
woo-hoo!</xsl:text>
<xsl:value-of select="."/>
</xsl:template>

Quoting "Bradley, Peter" <PBradley(_at_)uwic(_dot_)ac(_dot_)uk>:

Yeah.  This neatly sums up the problems I've been having.  An XPath
expression always seems to return an entire sub-tree, and it seems to me that
I just want a single node in this case.  Will xsl-copy give me that?

Peter

 -----Original Message-----
From:         Geert Josten [mailto:Geert(_dot_)Josten(_at_)daidalos(_dot_)nl] 
Sent: 08 November 2004 14:42
To:   xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject:      Re: [xsl] Conditional extraction of data

M. David Peterson wrote:

ooops!

This portion:

<xsl:value-of select="foo"/> will output: "this is the value of foo"

<xsl:value-of select="foo"/> will output a copy of all the text elements 
as well as the elements and there values that are descendants of foo. o

should have read...

<xsl:value-of select="foo"/> will output: "this is the value of foo"

Not true. xsl:value-of takes the first element from the node-set that results
from the expression 
"foo" and converts that to a string. As both sub elements <bar> and <p> are
_inside_ element <foo>, 
their textual content is returned as well.

The output is therefore: "
    this is the value of foo
    this is the value of bar.this is the value of a paragraph that is the
child of bar
"

(including new-lines when white-space is preserved)

<xsl:copy-of select="foo"/> will output a copy of all the text elements 
as well as the elements and there values that are descendants of foo.

Sorry for the confusion!

<M:D/>

Grtz,
Geert

--+------------------------------------------------------------------
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>
--+--