[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] node() function

Subject: Re: [xsl] node() function
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Jun 2014 13:51:38 -0000


Another explanation for the behavior is that this template:

<xsl:template match="node()">

will override the built-in template for text nodes:

<xsl:template match="text()">
  <xsl:value-of select="."/>

Of course it is that template that ordinarily accounts for why text
contents of the source are copied to the result.

But text nodes have no children, so when the context is a text node,
the xsl:apply-templates instruction has no effect (since no templates
are applied to any children).

This is why the OP's stylesheet 1 creates no output -- because
templates are applied all the way down, but none of them ever write
anything to the result.

The solution is not to use node() when you don't want to match (or
select) text nodes ... use *, processing-instruction(), comment()
instead. Or see to it that you have another template to override the
match on 'node()':

<xsl:template match="text()" priority='1'>
  <xsl:value-of select="."/>

Cheers, Wendell

Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables

Current Thread