[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Substituting a template for value-of

Subject: Re: Substituting a template for value-of
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Wed, 26 Oct 2011 11:46:58 +0100
Re:  Substituting a template for value-of
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.