Subject: RE: how to workaround restriction of overloading functions
From: Robby Pelssers <Robby.Pelssers@xxxxxxx>
Date: Tue, 17 Jul 2012 17:32:10 +0200
|
Damn...
I was already thinking along those lines but I wasn't sure if such approach
would work.
So let's assume I needed an uber-function that would return a sequence of
URI's, would sth like this work?
I want a list of all URI's stored in a variable uniqueURIs. Since I can't use
mode in a select statement like
<xsl:variable name="uniqueURIs" select="/maximo:*" mode="getURI"/>
I will probably need to call a function?
<xsl:variable name="uniqueURIs" select="znapz:getUniqueURIs(/maximo:*)"/>
<xsl:function name="znapz:getUniqueURIs">
<xsl:param name="elements" as="element(maximo:*)*"/>
<!-- should I apply-templates here now? This was the part which gets me
confused and I was thinking this might not work -->
<xsl:apply-templates select="$elements" mode="getURI"/>
</xsl:function>
<xsl:template match="maximo:crontask" mode="getURI" as="xs:anyURI">
<xsl:sequence select="'someURI_1'"/>
</xsl:template>
<xsl:template match="maximo:table" mode="getURI" as="xs:anyURI">
<xsl:sequence select="'someURI_2'"/>
</xsl:template>
-----Original Message-----
From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx]
Sent: Tuesday, July 17, 2012 5:18 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: how to workaround restriction of overloading functions
> Just double checking if there is a better way.
...
> <xsl:function name="znapz:getURI" as="xs:anyURI">
> <xsl:param name="element" as="element(maximo:SCRIPTLAUNCHPOINT)"/>
> <xsl:sequence
> select="{concat($destinationFolder, '/'SCRIPTLAUNCHPOINT/',
$element/maximo:AUTOSCRIPT, '.xml')}"/>
> </xsl:function>
>
> <xsl:function name="znapz:getURI" as="xs:anyURI">
> <xsl:param name="element" as="element(maximo:SECURITYRESTRICT)"/>
> <xsl:sequence
> select="{concat($destinationFolder, '/SECURITYRESTRICT/',
$element/maximo:APP, '.xml')}"/>
> </xsl:function>
The 'better way' is to use templates instead of functions here. Where
you currently call znaps:getURI() passing in the element,
apply-templates to it instead (in a mode) and let the template
matching mechanism take care of it.
--
Andrew Welch
http://andrewjwelch.com
|