Tutorial on how to make xslt 1.0 function?
This is an open discussion with 3 replies, filed under XSLT.
Search
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.
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:
Thank you for your help.