Re: [xsl] triggering xslt-functions from source

Subject: Re: [xsl] triggering xslt-functions from source
From: bryan rasmussen <rasmussen.bryan@xxxxxxxxx>
Date: Sat, 12 Nov 2005 10:15:09 +0100
Well the following:

<xsl:template match="fnc:*">
<xsl:variable name="localname" select="local-name()"/>
<xsl:variable name="locfunction"><root><xsl:copy-of select="ns:nodeset($
fncfunctions)/function[@name = $localname]"/>
</root></xsl:variable>
<xsl:variable name="fncnodeset"><xsl:for-each select="@*"><att
name="{name()}"><xsl:valueof
select="."/></att></xsl:for-each></xsl:variable>
<xsl:variable name="children"><xsl:copy-of select="child::*"/></xsl:variable>
<xsl:variable name="pass"><mmx:text><xsl:for-each select="ns:nodeset($
locfunction)/root/function/*">
<xsl:call-template name="fnc-processor"><xsl:with-param name="fncnodeset"
select="$fncnodeset"/><xsl:with-param name="children"
select="$children"/></xsl:call-template>
</xsl:for-each></mmx:text></xsl:variable>
<xsl:apply-templates select="ns:node-set($pass)/*"/>
</xsl:template>
<xsl:template name="fnc-processor">
<xsl:param name="fncnodeset"/>
<xsl:param name="children"/>
<xsl:choose>
<xsl:when test="self::att:*">
<xsl:variable name="locattname" select="local-name()"/>
<xsl:value-of select="ns:node-set($fncnodeset)/att[@name = $locattname]"/>
</xsl:when>
<xsl:when test="self::funx:apply">
<xsl:copy-of select="ns:node-set($children)/*"/>
</xsl:when>
<xsl:when test="self::funx:copyAtts">
<xsl:for-each select="ns:node-set($fncnodeset)/att"><funx:attribute
27
name="{@name}"><xsl:value-of select="."/></funx:attribute></xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="* | text()"><xsl:call-template
name="fnc-processor"><xsl:with-param
name="fncnodeset" select="$fncnodeset"/><xsl:with-param name="children"
select="$children"/></xsl:call-template></xsl:for-each>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

from a document grandiosely titled the OIOXML GTA Specifications at
http://www.oio.dk/dataudveksling/nyheder/vejledningtransformationsarkitektur

example usage from the document:

"Functions with funx make use of two other namespaces,
http://rep.oio.dk/funx/fnc for the
definition of funtions (which we will refer to as the fnc namespace
from now and for which we
will the use the prefix fnc), and http://rep.oio.dk/funx/fnc/att for
parameters passed through a
function. A function is held in the GTAconfig.xml under the following xpath
/config/functions/function and is referred to by an element in the fnc
namespace for example:
<fnc:twotimestwo/>

would process the function from the GTAconfig.xml file that would be
understood from the
following xpath /config/functions/function[@name='twotimestwo'] ,
which would hopefully be
defined in such a way as to return the number 4. If we wanted to do
something a little more
complicated for example just two times a parameter we pass in to the
function then the following
example:
<fnc:twotimes number='5'/>
and the function /config/functions/function[@name='twotimes'] was
defined as follows:
<function
name='twotimes'><funx:multiply><funx:arg>2</funx:arg><funx:arg><att:number/><
/funx:arg>
</funx:multiply></function>
then the example above would return 2*5."

in other words one has a configuration file holding functions such as
the one above
<function
name='twotimes'><funx:multiply><funx:arg>2</funx:arg><funx:arg><att:number/><
/funx:arg>
</funx:multiply></function>
which can then be called by <fnc:twotimes number='5'/> = namespace
qualified function name, parameters passed equals attributes. and so
forth.

Notice that the document provides syntax that matches the common
xslt/xpath built in functions, allowing for composability.

Although this document is officially released now it could definitely
be improved. I'm expecting to do the release some time in the next
couple weeks, after improvements of course. Also I have some other
documents that connect to it that I have not released yet, showing how
to work with transformation of  oioxml, a large national project
comprised of various namespaces and data elements, how to work with
FXSL, etc.

This document is as of now focused on XSLT 1.0 although I do have a
XSLT 2.0 version of  the 'funx' language.

I haven't put the actual implementations up yet, but most of the
implementation code is referenced in the document - although I expect
there will be the odd wrong quotation marks and stuff, put in by be
obliged to write in Microsoft Word at places.

Also I expect that there are still, as is always the case, further
proofreading errors in the document.




On 11/12/05, Manuel Baehnisch <s716631@xxxxxxxxxxxxx> wrote:
> Looks like I found one answer myself. The saxon:evaluate() function works.
> And as I read in Michaels book, there no other way in XSLT2.0.
>
> Manuel Baehnisch
>
> MB> I was wondering if it is possible to trigger xslt-functions out of the
> MB> source-tree.
>
> MB> Lets say your source-xml has an element as the following:
> MB> <foo function="xsl:tokenize(...)" parameters="..."/>
>
> MB> Is it somehow possible to use that as:
> MB> <xsl:value-of select="foo/@function"/>

Current Thread