Jump to content

How to use xsl:function


Recommended Posts

I have a standard transform for different elements within the document. The only differences between the transforms are css classes in the output. So, I'm trying to do something like this:

        <xsl:function name="xform:createStandOut" as="element()">         <xsl:param name="section"/>         <xsl:param name="title"/>         <p>             <span class="{concat('cls', $section)}">                 <table>                     <tr>                         <td class="{concat('cls', $section, 'Label')}"><span>$title:</span></td>                         <td><xsl:apply-templates/></td>                     </tr>                 </table>             </span>         </p></xsl:function>

And, then, to call it:<xsl:value-of select="xform:createStandOut('Note', 'NOTE')"/>I know I'm missing something fundamental... or taking thw wrong path altogether.... I suppose I could use xsl:if or xsl:choose in a multi-match template, but just wondering if a function should/could be used for such a thing.Joe

Link to comment
Share on other sites

Native function declarations are only available in XSLT 2. If you don't have an XSLT 2.0 processor, you can use exsl:function instead.To copy the elements that are declared in the function, you need to use <xsl:copy-of/> instead of <xsl:value-of/>. <xsl:copy-of/> preserves all nodes that are passed to it. <xsl:value-of/> gives only the string() output of it's argument.What's wrong about using a template instead of a function for that case anyway? Why not use

<xsl:template name="xform:createStandOut">...</xsl:template>

and call it like:

<xsl:call-template name="xform:createStandOut">	<xsl:with-param name="setion" select="'Note'"/>	<xsl:with-param name="title" select="'NOTE'"/></xsl:template>

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...