xsl-list
[Top] [All Lists]

Re: [xsl] [Xslt 3 Start] Use case for Function Call Invocation

2021-02-04 10:01:34
On Thu, Feb 4, 2021 at 12:24 AM Martin Honnen 
martin(_dot_)honnen(_at_)gmx(_dot_)de <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:


If you have a module/a function library you can use a function of it with
e.g.

let $xslt := <xsl:package xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
<http://www.w3.org/1999/XSL/Transform> version="3.0">
<xsl:import href="http://www.xsltfunctions.com/xsl/functx-1.0.1-nodoc.xsl";
<http://www.xsltfunctions.com/xsl/functx-1.0.1-nodoc.xsl>/>
<xsl:expose component="function" names="*" visibility="public"/>
</xsl:package>
return
transform(
    map {
        'stylesheet-node' : $xslt,
        'initial-function' : QName('http://www.functx.com',
'repeat-string'),
        'function-params' : ['x', 5]
    }
)?output

The XQuery part to first construct an XSLT 3 package importing the XSLT 2
functx library is only necessary as the XSLT 2 functions are otherwise not
public. If you had an XSLT 3 version of functx with public functions you
would just use the module with e.g. the transform function.


Contrast this with a simple XPath-function-library loader (the transform()
function isn't used at all):

<xsl:stylesheet version="3.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  xmlns:map="http://www.w3.org/2005/xpath-functions/map";
  xmlns:f="http://www.fxpath.org";>

  <xsl:variable name="vBaseFXpathUri"
    select="(environment-variable('FXpathDir')[normalize-space()],
'..')[1]"/>

  <xsl:function name="f:loadFunctionLibraries" as="map(*)"
visibility="public">
    <xsl:param name="pLibrariesUris" as="xs:string+"/>

    <xsl:variable name="vAllText" as="xs:string+" select=
      "string-join(
                  (for $p in $pLibrariesUris
                    return unparsed-text($p)
                  ),
                  ',&#xA;'
                 )"/>

    <xsl:evaluate xpath="'map:merge((' || $vAllText || '))'">
      <xsl:with-param name="pBaseFXpathUri" select="$vBaseFXpathUri"/>
    </xsl:evaluate>
  </xsl:function>
</xsl:stylesheet>


-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>