# 22. Virtuoso Functions Guide - xpf_extension

Chapter Contents | Prev | Next
Keyword Search:
www.openlinksw.com
docs.openlinksw.com
Book Home
Contents
Preface
Virtuoso Functions Guide
Administration
Aggregate Functions
Array Manipulation
BPEL APIs
Backup
Compression
Cursor
Date & Time Manipulation
Debug
Dictionary Manipulation
Encoding & Decoding
File Manipulation
Free Text
Hashing / Cryptographic
LDAP
Locale
Mail
Miscellaneous
Number
Remote SQL Data Source
Replication
SOAP
SQL
String
Transaction
Type Mapping
UDDI
User Defined Types & The CLR
Virtuoso Java PL API
Virtuoso Server Extension Interface (VSEI)
Web Server & Internet
XML
xmlagg
xmlattributes
xmladdattribute
xmlappendchildren
xmlconcat
xmlelement
xmlforest
xmlinsertafter
xmlinsertbefore
xmlreplace
xmltype.xmltype
xmltype.createnonsch...
xmltype.createschema...
xmltype.createxml
xmltype.existsnode
xmltype.extract
xmltype.getclobval
xmltype.getnamespace
xmltype.getnumval
xmltype.getrooteleme...
xmltype.getschemaurl
xmltype.getstringval
xmltype.isfragment
xmltype.isschemabase...
xmltype.isschemavali...
xmltype.isschemavali...
xmltype.schemavalida...
xmltype.setschemaval...
xmltype.toobject
xmltype.transform
xmlupdate
xper navigation
createxml
isentity
serialize_to_utf8_xm...
tidy_html
tidy_list_errors
updatexml
xml_add_system_path
xml_auto
xml_auto_dtd
xml_auto_schema
xml_create_tables_fr...
xml_cut
xml_doc_output_optio...
xml_get_system_paths
xml_load_mapping_sch...
xml_load_schema_decl
xml_namespace_scope
xml_persistent
xml_template
xml_tree
xml_tree_doc
xml_tree_doc_media_t...
xml_uri_get
xml_validate_dtd
xml_validate_schema
xml_view_dtd
xml_view_schema
xmlsql_update
xpath_eval
xper_cut
xper_doc
xper_locate_words
xpf_extension
xpf_extension_remove
xquery_eval
xslt
xslt_format_number
xslt_sheet
xslt_stale
xte_head
xte_node
xte_node_from_nodebl...
xte_nodebld_acc
xte_nodebld_final
xte_nodebld_init
xtree_doc
XPATH & XQUERY
Functions Index

## xpf_extension

declare an XPath extension function
void xpf_extension (in fname varchar, in procedure_name varchar);
Description

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 retreived as a strings and then will be converted to the datatype of the corresponding argument of the stored procedure.

Parameters
fname – The name of the extension function, which must be the expanded QName of the extension function
procedure_name – The fully qualified name of the PL procedure which acts as the extension function. The procedure in question must be granted to PUBLIC, otherwise it will not be registered and error will be signalled.
Return Types

None (void).

Errors

SQLState | Error Code | Error Text | Description
--- | --- | --- | ---
42001 | XPE01 | The function <procedure_name> does not exists | if procedure to define as a XPATH extension function is not existing one.
42001 | XPE02 | The <built-in XPATH|XQUERY> function "<func name>" cannot be re-defined | if XPATH or XQUERY function to be registered is a core function.

Examples
Declaring a New XSLT Function

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'.

See Also

xpf_extension_remove