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:52:43 +0100
an attribute or a text node with no children ..
>
> Text nodes don't have children... (pedant time :)

You are right... I meant Nodes with no children..
> Just to be clear for the archives, value-of doesn't 'print text
> values', it will add a single text node to the result tree.  That
> single text node will be the string value of whatever was in the
> select attribute or body of the value-of.

:-) Ok....you are right... I will think about the right words next time :)

> I disagree here... it's not some risky practice only to be undertaken
> by experienced devs, it's just good practice.  If devs know they
> should be doing it, but are not sure why, that's fine... better to
> learn about template matching and the default templates sooner than
> later.
>
I am not sure what you are dissagreeing upon ,,,

On 26 October 2011 11:46, Andrew Welch <andrew.j.welch@xxxxxxxxx> wrote:
> Hi Vasu,
>
> On 26 October 2011 11:20, Vasu Chakkera <vasucv@xxxxxxxxx> wrote:
>> The only safe usage for xsl:value-of select is when you are selecting
>> an attribute or a text node with no children ..
>
> Text nodes don't have children... (pedant time :)
>
>> 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..
>
> Just to be clear for the archives, value-of doesn't 'print text
> values', it will add a single text node to the result tree.  That
> single text node will be the string value of whatever was in the
> select attribute or body of the value-of.
>
>> 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)
>
> Yep, which is why you should use apply-templates.  You could use
> xsl:for-each, but then you aren't opening the code up for overriding,
> so you may have to come back to that bit of code and rewrite it.
>
>> 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..
>
> I disagree here... it's not some risky practice only to be undertaken
> by experienced devs, it's just good practice.  If devs know they
> should be doing it, but are not sure why, that's fine... better to
> learn about template matching and the default templates sooner than
> later.
>
>
> --
> Andrew Welch
> http://andrewjwelch.com
>
>



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

Current Thread