xsl-list
[Top] [All Lists]

Re: [xsl] XSLT 2.0: When to use xsl:sequence, when to use xsl:value-of, and why?

2007-06-16 10:03:42
On Sat, 16 Jun 2007 10:18:45 -0600, Florent Georges <darkman_spam(_at_)yahoo(_dot_)fr> wrote:

    <xsl:stylesheet
        xmlns:xsl="http://www.w3c.org/1999/XSL/Transform";
        version="2.0">
     <xsl:variable name="elem" as="element()">
        <elem a="value"/>
      </xsl:variable>
     <xsl:template match="/">
        <xsl:sequence select="$elem/@a"/>
      </xsl:template>
   </xsl:stylesheet>

Thanks for this, Florent! I guess more of what I was asking was along the lines of given two scenarios where, as far as a human is concerned, the output is the same, would it be preferable to use xsl:sequence or xsl:value-of? For example,

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

    <xsl:variable name="elem" as="element()">
        <elem>foo</elem>
    </xsl:variable>

    <xsl:template match="/">
        <xsl:sequence select="$elem/text()" />
    </xsl:template>

</xsl:stylesheet>

and

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

    <xsl:variable name="elem" as="element()">
        <elem>foo</elem>
    </xsl:variable>

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

</xsl:stylesheet>

will both produce 'foo' in the final serialized output. In this regard, is there a reason why one might use xsl:sequence over xsl:value-of or vice-versa?

--
/M:D

M. David Peterson
http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--