I'm using Saxon HE's XPathCompiler class in VB .NET to run XPath queries against an XML file, and then processing the results. I also have an XSL with user-defined functions. Is there a way I can reference these user-defined functions in my XPath queries? I'm successfully referencing them from other XSLs, but unsure how to do it when I'm just executing XPath queries on their own from a Saxon XPathCompiler object.
Basically, I'm hoping there's some way in the following code that I can point at my DocOpsFunctions.xsl stylesheet and access the functions defined there.
Code:
Dim myProcessor As New Saxon.Api.Processor
Dim myCompiler As XPathCompiler = myProcessor.NewXPathCompiler()
myCompiler.XPathLanguageVersion = "3.1"
Dim myDocBuilder As DocumentBuilder = myProcessor.NewDocumentBuilder
Dim myDoc As XdmNode = myDocBuilder.Build(New Uri("input.xml"))
Dim myResults As XdmValue
myResults = myCompiler.Evaluate("dof:lefttrim('ISTeams/Team'", myDoc)
DocOpsFunctions.xsl:
<xsl:transform version="3.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:dof="http://docops.com">
<xsl:function name="dof:lefttrim" as="xs:string">
<xsl:param name="text"/>
<xsl:value-of select="replace($text, '^\s+', '')"/>
</xsl:function>
</xsl:transform>
Input.xml:
<ISTeams>
<Team>Team1 </Team1>
<Team>Team2 </Team2>
</ISTeams>
I'm aware of the ability to define extension functions using the ExtensionFunction interface, but am hoping to find a way to do this more dynamically, so that new functions can be implemented in the stylesheet instead of in the code.