atom feed9 messages in net.sourceforge.lists.saxon-helpRe: [saxon] Question about the Expres...
FromSent OnAttachments
Paul RyanAug 8, 2012 9:09 pm 
Michael KayAug 8, 2012 11:07 pm 
Paul RyanAug 9, 2012 6:17 am 
Paul RyanAug 9, 2012 7:24 am 
Michael KayAug 9, 2012 8:28 am 
Michael KayAug 9, 2012 8:50 am 
Paul RyanAug 9, 2012 9:15 am 
Paul RyanAug 9, 2012 9:15 am 
Michael KayAug 9, 2012 1:36 pm 
Subject:Re: [saxon] Question about the Expression Java API for XSLT
From:Michael Kay (mi@saxonica.com)
Date:Aug 9, 2012 8:28:50 am
List:net.sourceforge.lists.saxon-help

The idea of the CodeInjector interface is that you supply a CodeInjector, and the XPath parser calls the inject() method to process each expression on the expression tree; your CodeInjector then has the option of returning the original expression unchanged, or constructing a new expression (which will typically produce the same result as the original, but perhaps with side-effects like outputting trace information or checking for a debugging breakpoint). You should not be calling the inject() method yourself from the application level.

There isn't any direct way of supplying a CodeInjector when you are using the JAXP XPath interface (or, for that matter, when using the s9api interface). I think the only way to do it is to call the static method ExpressionTool.make(), which is a rather low-level interface.

The XSLTTraceCodeInjector isn't much use to you because it only injects code at the level of XSLT instructions, not within an XPath expression. Using the class TraceCodeInjector would make more sense; but I suspect a better approach would be write your own implementation of CodeInjector (you could use TraceCodeInjector as a model).

If you only want to wrap the parsed expression by some construct of your own at the outermost level, then you don't need the code injector at all. You could simply wrap the Expression returned by the XPath parser inside a TraceExpression.

Michael Kay Saxonica

On 09/08/2012 15:24, Paul Ryan wrote:

I've been attempting a few more things based on your last statements and it's starting to appear that maybe I need to construct the item with a context major but I may be completely wrong is something like the following more what you would expect:

XSLTTraceCodeInjector injector = (XSLTTraceCodeInjector)this.getCodeInjector(); StructuredQName qname = newStructuredQName("trace", "http://www.myuri.com/extension/trace", "trace"); //StructuredQName qname = new StructuredQName("", "", "trace"); StaticContext staticContext = new JAXPXPathStaticContext(currentItem.getConfiguration()); ContextItemExpression expression = new ContextItemExpression();

injector.inject(expression, staticContext, StandardNames.XS_ELEMENT, qname); try { XPath xpath = XPathFactory.newInstance().newXPath(); XPathExpression xpathExpr = xpath.compile("/foo/bar"); InputSource someXML = new InputSource(new StringReader("<someXML>...</someXML>")); Item item = (Item) xpathExpr.evaluate(someXML, XPathConstants.NODE); XPathContextMajor majorContext = new XPathContextMajor(item, new Executable(context.getConfiguration()));

expression.evaluateItem(majorContext); } catch (XPathException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); }

Note: This is not functional; I'm getting a context item not set XPathException from the evalueteItem call in the expression, more I'm wondering if this is closer to the path I need to take for the use case I described in the previous email...

Again thanks for the help with this,

-- Paul Ryan

On Aug 9, 2012, at 9:17 AM, Paul Ryan wrote:

I think it looks like I'm trying to do something out of scope because I don't quite understand the usage of inject. Our use case is for debugging instrumentation (not so much performance), we want to construct a node that contains some information about construction of an area of code. We have the information for about this run pulled form tracelistener callbacks and other sources we have available in our system. So I guess a large part of my problem here is that I'm not completely sure how these methods are intended to work. I currently have this code in an enter function in an XSLTTraceListener.

It sounds like what your saying is that the expression.process needs to be run after the inject which then leads me to the question of how would I go about adding information to the item to be injected? Is it even possible to add information to the code surrounding the current context (via the enter)?

Thanks again for your patience and help as I learn about this set of APIs,

On Aug 9, 2012, at 2:08 AM, Michael Kay wrote:

The code injector mechanism in the Saxon expression parser is intended to allow injection of code that can be used for tracing and debugging, or perhaps for performance instrumentation. From your description it's not at all clear to me what you are trying to achieve or why you think this API might be an appropriate way of achieving it. Apart from anything else, you are calling inject() to modify the compiled XPath expression after the expression has already been executed, which will obviously have no effect.

I think you need to step back and explain more carefully what you are trying to achieve.

On 09/08/2012 05:09, Paul Ryan wrote:

I have an XPathContext that points to a location in the model XML and InstructionInfo that tells about a trace listener instruction in the trace listener. I'm trying to construct a node in memory to put in the XML but am not having luck.

I've tried:

XSLTTraceCodeInjector injector = (XSLTTraceCodeInjector)this.getCodeInjector(); StructuredQName qname = newStructuredQName("trace", "http://anamespace/extension/trace", "trace"); StaticContext staticContext = new JAXPXPathStaticContext(currentItem.getConfiguration()); ContextItemExpression expression = new ContextItemExpression();

try { expression.process(context); } catch (XPathException e) { // TODO Auto-generated catch block e.printStackTrace(); } injector.inject(expression, staticContext, StandardNames.XS_ELEMENT, qname);

which just injects the document as a whole into the context point. I'm not having any luck understanding the expression syntax in this user story I've tried to construct other contexts without a result. Any help would be appreciated.

Thanks,

------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats.http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/