Re: [xsl] why not match text()? (fork from "Novice Question - matching entire text children")

Subject: Re: [xsl] why not match text()? (fork from "Novice Question - matching entire text children")
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Tue, 21 Dec 2010 10:33:32 +0000
This might be a common problem from people coming from XQuery... in
XSLT we get the string value of the element or attribute, in XQuery
you get the deep-copy, so there is the habit of specifying string()
everywhere (or text() in the past)
Yes. In XSLT it's natural to do

<book><xsl:value-of select="title"/></book>

In XQuery it's best to do

<book>{string(title)}</book>

but many examples and tutorials encourage

<book>{title/text()}</book>

which works fine until someone has a title that reads:

<title>On the freezing point of H<sub>2</sub>O</title>

As to using template rules that match text nodes, I think the discussion we've been having shows that it's legitimate if you have mixed content and need to something with the content of the text other than copying it or discarding it; but you do need to be aware that the text can be split up into multiple text nodes by comments or other markup.

Michael Kay
Saxonica

Current Thread