[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [xslt 2.0] Difference betwen functions and templat
Hi Justin, I agree with you, that "xsl:template match= ..." is the essence of XSLT. Without it, XSLT cannot work. I feel, it's interesting to discuss the differences between "xsl:template name= ..." and xsl:function. Both are callable components, and are sort of subroutines (they, actually are). Are both of these needed in XSLT 2.0, or we can just have xsl:function or xsl:template name= ... As we have already discussed, xsl:function (a user-defined function) can be called only from within a XPath expression (something like, /abc/pqr[xx = ns:func()]/uvw (this is a new thing in XSLT/XPath 2.0, and is a very useful innovation). But, xsl:template name= ... *cannot* be called from a XPath expression. Now the questions is, is xsl:template name= ... able to do something, which xsl:function cannot do? Yes, xsl:template name= has some features, which xsl:function doesn't have. Please consider the below example: <?xml version="1.0"?> <xsl:stylesheet xmlns:xx="http://dummy-ns" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <result> <xsl:call-template name="dummy-template" /> </result> </xsl:template> <xsl:function name="xx:dummy-func" as="node()+"> <dummy-content/> </xsl:function> <xsl:template name="dummy-template"> <dummy-content/> </xsl:template> </xsl:stylesheet> I am calling a named template, using xsl:call-template. The output of this stylesheet is: <?xml version="1.0" encoding="UTF-8"?> <result xmlns:xx="http://dummy-ns"> <dummy-content/> </result> Can we do a similar thing using xsl:function? We cannot.. For example, will this work? [1] <xsl:template match="/"> <result> xx:dummy-func() </result> </xsl:template> or, will this work? [2] <xsl:template match="/"> <result> <xsl:value-of select="xx:dummy-func()" /> </result> </xsl:template> (xsl:value-of constructs a text node, so this won't work) I would have considered xsl:function and xsl:template name= ... to be equivalent, if [1] produced the same output as, xsl:call-template. My conclusion therefore is, xsl:function and xsl:template name= are very different, and both are required in XSLT 2.0. On 7/19/07, Justin Johansson <procode@xxxxxxxxxx> wrote: Mukul, -- Regards, Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|