tags:

views:

331

answers:

2

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.

A: 

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)" />
bzlm
+1  A: 

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.