xsl-list
[Top] [All Lists]

RE: [xsl] how to workaround restriction of overloading functions

2012-07-17 10:32:25
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(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com] 
Sent: Tuesday, July 17, 2012 5:18 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--