Re: [xsl] Substituting a template for value-of

Subject: Re: [xsl] Substituting a template for value-of
From: Vasu Chakkera <vasucv@xxxxxxxxx>
Date: Wed, 26 Oct 2011 11:20:15 +0100
The only safe usage for xsl:value-of select is when you are selecting
an attribute or a text node with no children ..
value of select on a node with children will print text values of all
the children including the whitespace nodes, this in most cases may be
undesirable as you have no control over what goes in the result tree
for these nodes.. for nodes with child nodes.. you need a mechanism of
"node-visiting", which is either using a for-each or an
apply-templates. IN for each, the node behavior is in the body of the
for-each and in apply-templates , the node behavior is in a template.
if no template is defined, then the default template rules come into
play..( Again, this may be not so much desirable, as most often, you
may want to control  what goes intot he result tree for each of the
nodes visited)

These behaviors should be well understood before substituting the
xsl:apply templates with value-of or vice-versa, as both are designed
for different outcomes. although the  effects of these may be the same
under certain circumstances..




On 26 October 2011 10:32, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
> On 26 October 2011 07:28, Vasu Chakkera <vasucv@xxxxxxxxx> wrote:
>> You will have to really know when the value-of can be used instead of
>> the xsl:apply-templates. This can not be done at all times.
>
> Yeah it's just a general good practice thing... in summary:
>
> - if you are adding a text node to the result tree by selecting
> something from the input, use apply-templates
>
> - if you are adding a text node to the result by constructing a
> string, say using concat() or formate-date() etc, then xsl:value-of is
> fine... (however I think in 3.0 we will be able to apply-templates to
> atomics, so new techniques might arise from that)
>
> - if you are constructing a string in a function or say in the body of
> a variable, where the sequence type is an atomic, you should use
> xsl:sequence and not xsl:value-of.
>
>
>
>
> --
> Andrew Welch
> http://andrewjwelch.com
>
>



--
Vasu Chakkera
NodeLogic Limited
Oxford
www.node-logic.com
==============

Current Thread