Re: [xsl] xsl:sequence

Subject: Re: [xsl] xsl:sequence
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 9 Aug 2006 13:44:10 +0100
me> xsl:value-of returns the string value of an element, and that isn't
me> obtainable from xsl:sequence (without doing a lot of work that the
me> system has already done)

>  Do you mean that in "to/an/element/string()", 
hey that's cheating:-)

That is exactly the same as value-of (except it returns a string rather
than a text node) but wasn't what I meant here. As that is again just
selecting the element and allowing the system to return its string
value. I was comparing this with selecting
 or more generally
which is what tom tom was suggesting to use in xsl:sequence. So here you
just have sequence of child nodes. it is of course possible to
recursively traverse this sequence until you get to the text node
leaves, and then build up the string "by hand" but it's not often you
want to do that. More often, if value-of doesn't give you what you want
directly then you use apply-templates anyway, which is more flexible:

<xsl:value-of select="p"/> on 
<p><i>This</i> is <b>bold</b> text</p>
gives you a text node "This is bold text" which is fine but

<xsl:value-of select="p"/> on 
<p>This<br/>is an image: <img alt="flower" src="flower.png"/></p>
a text node "Thisis an image "
which is less fine so it's better to go
<xsl:apply-templates select="p"/>
and have
<xsl:template match="br"><xsl:text>&#10;</xsl:text></xsl:template>
<xsl:template match="img">[<xsl:value-of select="@alt"/>]</xsl:template>
then you get
is an image: [flower]"


Current Thread