Question

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

I know you have access to an XPathContext but is this 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 do we get the entire XML tree?

Edit: To clarify: I'm creating a custom function that ends up executing static Java code (it's a Saxon feature). So, in this Java code, I wish to be able to get elements from the XML tree, such as bar and fizz, and their CDATA, such as smang and buzz.

Was it helpful?

Solution

Try changing your XSL so you call 'ourFunction(/)'. That should pass the root node to the function. You could also try . or ..

You'll presumably need to change the signature of the implementing function, I'll let someone else help with that.

OTHER TIPS

What about select the current node selecting the relevant data from the current node into an XSL parameter, and passing that parameter to the function? Like:

<xsl:value-of select="ourFunction($data)" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top