This function is used to declare a new XPath extension function or redefine an existing function. It can be used in XPath queries and XSLT stylesheets. You should use QNames for extension functions. Note that the standard XPath functions cannot be redefined.
xpf_extension() stores the functions into the SYS_XPF_EXTENSIONS system table.
CREATE TABLE DB.DBA.SYS_XPF_EXTENSIONS ( XPE_NAME VARCHAR PRIMARY KEY, XPE_PNAME VARCHAR )
The input parameters will be retrieved as a strings and then will be converted to the datatype of the corresponding argument of the stored procedure.
None (void).
First define a PL procedure, then declare an XPath extension function and to represent it.
SQL> create procedure DB.DBA.str_concat (in a varchar, in b varchar) { return concat (a, ':', b); }; SQL> xpf_extension ('http://www.openlinksw.com/virtuoso/xslt:concat_strings', 'DB.DBA.str_concat');
The source of the ([http_root]/ext.xsl) XSLT stylesheet
<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns:virt="http://www.openlinksw.com/virtuoso/xslt"> <xsl:template match="/doc"> <HTML> <BODY> <xsl:if test="function-available('virt:concat_strings')"> <xsl:value-of select="virt:concat_strings ('foo', 'bar')"/> </xsl:if> </BODY> </HTML> </xsl:template> </xsl:stylesheet>
The source of the ([http_root]/ext.vsp) VSP page:
<?vsp http_xslt ('file:/ext.xsl'); ?> <doc> <a/> </doc>
This will produce the following HTML page:
<HTML><BODY>foo:bar</BODY></HTML>
Using the definition of the XPath extension function, we can include it in XPath expressions.
SQL> select p from ws..sys_dav_res where xpath_contains (RES_CONTENT, '[xmlns:virt=''http://www.openlinksw.com/virtuoso/xslt''] virt:concat_strings (''Title '', string(/chapter/title))', p);
This will return the contents of any '/chapter/title' nodes, prefixed with constant string 'Title'.