tags:

views:

93

answers:

2

How to call XSLT templates inline: So, Instead of :

<xsl:call-template name="myTemplate" >
<xsl:with-param name="param1" select="'val'" />
</xsl:call-template>

I can use XSLT built-in function-call sytle, like this:

<xls:value-of select="myTeplate(param1)" />
A: 

The syntax of XSLT is correct in the first example. You could also write

<xsl:call-template name="myTemplate" >
<xsl:with-param name="param1">val</xsl:with-param>
</xsl:call-template>

I am not sure what you are trying to do in the second code snippet (the 'val' is missing and there are two typos (xls, and myTeplate)) but it is not valid XSLT.I n

UPDATE If I now understand your question it was not "is there an alternative syntax for XSLT templates?" but "can I write my own functions in XSLT?".

Yes, you can. Here is a useful introduction. Note that you have to provide your Java code in a library and this may not be easy to distribute (e.g. in a browser). Try http://www.xml.com/pub/a/2003/09/03/trxml.html

peter.murray.rust
To call normalize-spaces built-in function, we pass the parameter as (param1, param2, paramn), Is there any way to call my template that way :<xsl:value-of select="myTemplate(param1, param2)" />
Mohammed
No. The syntax of builtin functions (e.g. normalize-spaces) is different from the syntax of templates.
peter.murray.rust
So, There is any way to create functions in XSLT?
Mohammed
Don't mistake XPath function for XSLT function; normalize-space() is a XPath function.
Erlock
Thanks, and sorry for mistake as i am a new to XSLT :)thanks.
Mohammed
+2  A: 

In XSLT 2.0 you can define your own custom functions using xsl:function

An article on XML.com describing how to write your own functions in XSLT 2.0: http://www.xml.com/pub/a/2003/09/03/trxml.html

<xsl:stylesheet version="2.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:foo="http://whatever"&gt;

  <!-- Compare two strings ignoring case, returning same
       values as compare(). -->
  <xsl:function name="foo:compareCI">
    <xsl:param name="string1"/>
    <xsl:param name="string2"/>
    <xsl:value-of select="compare(upper-case($string1),upper-case($string2))"/>
  </xsl:function>

  <xsl:template match="/">
compareCI red,blue: <xsl:value-of select="foo:compareCI('red','blue')"/>
compareCI red,red: <xsl:value-of select="foo:compareCI('red','red')"/>
compareCI red,Red: <xsl:value-of select="foo:compareCI('red','Red')"/>
compareCI red,Yellow: <xsl:value-of select="foo:compareCI('red','Yellow')"/>
  </xsl:template>

</xsl:stylesheet>
Mads Hansen