Jump to content

How to use xsl:function


javajoemorgan
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...