A more specific comment on your code and why it isn't working.

Firstly, your call on inject() does nothing. At best it would return an expression that wraps the ContextItemExpression you supplied as input; but the version of inject() in the XSLTTraceCodeListener implementation will return the ContextItemExpression unchanged. But it doesn't matter what it returns, because you never use the result in your program. If the injector returned a different expression, and if you evaluated the new expression returned by inject() instead of the original one, then it might achieve a useful effect. But even then, it would be far easier to just wrap the expression in 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 = new StructuredQName("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,

-- Paul Ryan

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.

Michael Kay
Saxonica


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 = new StructuredQName("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,

-- Paul Ryan



------------------------------------------------------------------------------
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/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 

------------------------------------------------------------------------------
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/_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
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/_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



------------------------------------------------------------------------------
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/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help