Title: Message
Hi All,
 
I am trying to implement an extension element like this:
  <ext:field select="..."  myattr1="..." myattr2="..."/>
where the select should be able to contain anything that would normally be valid
in an <xsl:value-of select="..."/> _expression_.
 
I have got this mostly working, but my code fails for this type of thing:
 
<xsl:variable name="foo" select="'some value'"/>
<ext:field select="$foo"/>
 
My code which evaluates the specified select statement reports that the variable
"foo" cannot be found, though XPath expressions are evaluated correctly
(as far as I can see). Variable "foo" is definitely in scope; replacing a call to my
extension with code like <xsl:value-of select="$foo"/> works fine.
 
Within my extension element method, I use the following code (mostly grabbed
from the PipeDocument code):
 
XPathContext xpContext = procContext.getTransformer().getXPathContext();
XPath dynamicXPath = new XPath(
  selectStr,
  xpContext.getSAXLocator(),
  xpContext.getNamespaceContext(),
  XPath.SELECT,
  procContext.getTransformer().getErrorListener());
 
XObject xobj = dynamicXPath.execute(
  xpContext,
  procContext.getContextNode(), // I suspect this is the problem
  xpContext.getNamespaceContext());
 
Note that global variables can be accessed from the select _expression_, just not
variables declared in the same template as the extension element invocation.
 
My suspicion (which may be wildly wrong) is that the node returned by procContext.getContextNode()
is the template node, not the <ext:field> node. And of course any variables declared
within that node are therefore not in scope.
 
Does anyone have any suggestions how to deal with this?
I cannot find any methods that would return the <ext:field> node itself, and am not sure
that if I did find one then xpath expressions might not be right if I used it. Note also that
the select _expression_ might be *any* valid _expression_.
 
On a related question, I am somewhat confused about what node getContextNode()
is returning anyway :-)
 
I am assuming the following:
* a DOM (or DOM-equivalent) has been built for the source xml document
* a DTM tree of "wrapper" nodes is built; each node has a reference back to the
   underlying source document node. It is to this DTM tree that any XSL variables are
   attached.
* the getContextNode() method returns a reference to the DTM node which wraps
  the currently matched source document node.
 
Could someone kindly correct me if I am off-beam here? Or maybe refer me to
an appropriate architectural document?
 
Many thanks in advance,
 
Simon

Reply via email to