Subject: Re: [xsl] Can a named template return a node list? From: John <john-xsl-list@xxxxxxxx> Date: Thu, 16 Jun 2005 07:47:36 -0700 |
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:template match="*"> <xsl:variable name="somedata"> <xsl:call-template name="sometemplate" /> </xsl:variable> <xsl:variable name="somenode" select="msxsl:node-set( $somedata )" /> <xsl:value-of select="$somenode/@attr" /> </xsl:template>
<xsl:template name="sometemplate"> <xsl:copy-of select="/root/node1" /> </xsl:template>
<root> <node1 attr="node1attrval"> <node1a>node1atext</node1a> </node1> <node2 attr="node1attrval"> <node2a>node2atext</node2a> </node2> </root>
<xsl:variable name="somenode"> ....
xsl:variable with content and no select attribute always (in xslt1) generates a result tree fragment not a node set. Therefor you can not query into the variable using XPath (or anything else) You can only copy it to the result, using copy-of or use it as a string.
and I am hoping to stay away from XSL extensions if possible.
It's hard to avoid xx:node-set() (which is designed exactly to get round this problem) Most systems have a node-set() extension function (with mozilla's transformiix engine being the main exception)
Of course if your templates are not actually creating any new nodes (as in your example) then you have an easy solution: just use xsl:variable with select as in
<xsl:template match="*"> <xsl:variable name="somenode"select="/root/node1" /> <xsl:value-of select="$somenode/@attr" /> </xsl:template>
David
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Can a named template retu, David Carlisle | Thread | Re: [xsl] Can a named template retu, Dimitre Novatchev |
Re: [xsl] Can a named template retu, Dan | Date | RE: [xsl] Can a named template retu, Michael Kay |
Month |