RE: [xsl] text() and not()

Subject: RE: [xsl] text() and not()
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 11:54:29 -0000
> I have two points:
>
> 1.  //*[not(name()='title')] matches all elements apart from
> the text in <title>

The text in <title> isn't an element, it is text.
To be pernickety, you should really write this as //*[not(self::title)] to
avoid namespace problems.
>
>     //text()[not(name()='title')] matches all text, including that in
> <title>
>
> What xpath do I need to use to stop all text except that in <title>?

The name() of a text node is always "". You want

//text()[not(parent::title)]

or alternatively

//*[not(self::title)]/text()

>
> 2.  If I use the default template to output the contents of
> <title>, how do
> I obtain the same sort of result as:
>
> <xsl:template match="para0/title">
>   <p class="title"><xsl:value-of select="."/></p>
> </xsl:template>
>
I don't understand. If you use the default (Built-in) template rule to
output <title> elements, it will just output the textual content of the
<title> element. If you want to wrap it in a <p> element, you must use a
template rule like the one you've shown us, you can't use the built-in
template rule.

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread