RE: [xsl] defining namespace / functions (XSLT 1)

Subject: RE: [xsl] defining namespace / functions (XSLT 1)
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 23 Feb 2004 21:03:11 -0000
The drawback to this is that in XSLT 1.0, you can't really return a
value from a template; you can only write nodes to the current result
tree. You can capture this result in an xsl:variable, but this will
always create copies of nodes rather than references. xsl:function in
XSLT 2.0 handles this much better.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Kaleb Pederson
> Sent: 23 February 2004 18:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] defining namespace / functions (XSLT 1)
> 
> 
> I currently have some stylesheets that make use of various extension 
> functions, but I would like to hide them in a 
> namespace/function so I can 
> simply call a single function that will handle the 
> implementation details.  
> What would be the best way of going about this?
> 
> I'm fairly new to XSLT, but think the following would work:
> 
> <xsl:template name="my:node-set">
> 	<xsl:param name="inval"/>
> 	<xsl:if test="$inval != ''">
> 		... choose the right extension / function ...
> 		... pass $inval as parameter ...
> 	</xsl:if>
> </xsl:template>
> 
> If I were to do this, and in the case that I return a 
> node-set, would I still 
> be able to perform all the standard XPath queries on it or 
> would it somehow 
> get converted to a result set?  This implementation seems to have its 
> limitations, but is better than having many identical 
> xsl:choose statements 
> in there.
> 
> I've found some archived messages by Jeni and others 
> indicating that some 
> discussions were in place (about three years ago) to allow 
> the creation of 
> functions?
> 
> Any suggestions? Any good links?
> 
> Thanks for the help.
> 
> --Kaleb
> PS: a sample of one of my current methodologies follows
> 
> ///////// my stylesheet currently has something like 
> //////////// <xsl:choose>
> 	<!-- search for the various node-set functions -->
> 	<xsl:when test="function-available('msxsl:node-set')">
> 		<xsl:apply-templates
> 			
> select="msxsl:node-set($sorted-pages)/site-indexed-content" />
> 	</xsl:when>
> 	<xsl:when test="function-available('xalan:nodeset')">
> 		<xsl:apply-templates 
> 			
> select="xalan:nodeset($sorted-pages)/site-indexed-content" />
> 	</xsl:when>
> 	<xsl:when test="function-available('exsl:node-set')">
> 		<xsl:apply-templates
> 			
> select="exsl:node-set($sorted-pages)/site-indexed-content" />
> 	</xsl:when>
> 	<xsl:otherwise>
> 		<xsl:text>The XML implementation in use is not 
> supported</xsl:text>
> 	</xsl:otherwise>
> </xsl:choose>
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread