Retrieving XML Data Inside an XPath Custom Function

Is there a way to get the current xml data when we create our own XPath function (see here).

I know that you have access to XPathContext , but is that enough?

Example:

Our XML:

 <foo> <bar>smang</bar> <fizz>buzz</fizz> </foo> 

Our XSL:

 <xsl:template match="/"> <xsl:value-of select="ourFunction()" /> </xsl:template> 

How to get the whole XML tree?

Edit: To clarify: I am creating a custom function that finishes executing static Java code (this is a Saxon function). So in this Java code, I want to be able to get elements from an XML tree, such as bar and fizz, and their CDATA, for example smang and buzz.

+4
source share
2 answers

Try changing the XSL so that you call 'ourFunction (/)'. This should pass the root node to the function. You can also try. or..

You will probably have to change the signature of the implementation function, I will let someone else help with this.

+1
source

How about choosing the current node, selecting the appropriate data from the current node in the XSL parameter, and passing this parameter to the function? How:

 <xsl:value-of select="ourFunction($data)" /> 
+1
source

Source: https://habr.com/ru/post/1276728/


All Articles