1 users online. Create an account or sign in to join them.Users

Search

I've been using functions in exslt for sometime now and wondered if any of those in the forum who are more advanced in their xslt 1.0 skills could help me learn how to create my own functions so that I'm not calling templates but creating a name space and accessing those templates something like the following:

<xsl:value-of select="myns:templatename(param1, param2...)"/>

Thank you for your help.

Take the following code and put in "/workspace/utilities/wjnielsen.xsl":

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wjnielsen="http://getsymphony.com/functions"
    xmlns:func="http://exslt.org/functions"
    extension-element-prefixes="func">

    <func:function name="wjnielsen:concat">
        <xsl:param name="string1" select="''"/>
        <xsl:param name="string2" select="''"/>

        <func:result>
            <xsl:value-of select="concat(string1,' - ',string2)"/>
        </func:result>
    </func:function>

</xsl:stylesheet>

You must declare the func namespace:

xmlns:func="http://exslt.org/functions"

You must declare your arbitrary namespace:

xmlns:wjnielsen="http://getsymphony.com/functions"

The format for a function is this:

<func:function name="wjnielsen:__function-name__">
    __params__

    <func:result>
        __result-output-here__
    </func:result>
</func:function>

In your page, put this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wjnielsen="http://getsymphony.com/functions"
    extension-element-prefixes="wjnielsen">

    <xsl:import href="../utilities/wjnielsen.xsl"/>

    <xsl:template match="/">
        <xsl:value-of select="wjnielsen:concat('Will Nielsen', 'entrepreneur 4 life')"/>
    </xsl:template>

</xsl:stylesheet>

Quoting from @brendo and others: Dance :)

@VladG Thank you for taking the time to teach me. Much appreciation. I called the ambulance before I started dancing (just in case my back went out).

This is so utterly cool! I wish I had seen this before.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.1
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details