Menu

Text Nodes do not appear in Trace API events

Help
Gabor Guta
2010-03-08
2012-10-08
  • Gabor Guta

    Gabor Guta - 2010-03-08

    I have written a class which implements the net.sf.saxon.trace.TraceListener
    interface. It works fine, but it doesn't emit any event in case of text nodes.
    Can anybody suggest some workaround? I need a tracein which I can see which
    instruction (or element) in the XSLT produces which part of the output.

    Thanks, Gabor

     
  • Michael Kay

    Michael Kay - 2010-03-10

    You appear to be correct; literal text output is not notified to the
    TraceListener. I'll look at adding this in a future release. I'm reluctant to
    do it in a maintenance patch because it could disrupt users who have working
    TraceListener code, for example the debuggers in Stylus Studio and Oxygen.

     
  • Gabor Guta

    Gabor Guta - 2010-03-10

    Approximately how long does it take? Can you provide a separated patch?

    Thank you for your quick answer!
    Gabor

     
  • Michael Kay

    Michael Kay - 2010-03-10

    I'll investigate this in more detail when I'm back in the office next week.

     
  • Michael Kay

    Michael Kay - 2010-03-15

    I've raised a bug and patch on this:

    2970599 Literal text nodes in stylesheet not traced

    The text node will be traced as if it were wrapped in an xsl:text instruction.
    The actual InstructionInfo passed is the ValueOf instruction; where this is
    literal text, its getSelect() method returns a StringLiteral object containing
    the text to be output.

     
  • Gabor Guta

    Gabor Guta - 2010-04-20

    It seems that the info.getColumnNumber() and info.getLineNumber() return the
    start position of the dynamic context instead of the position of the element
    in the enter/leave(InstructionInfo info) callback. Is it possible to fix this
    or these information are already dropped at that point?

     
  • Michael Kay

    Michael Kay - 2010-04-20

    In my tests the line numbers appear to be correct. You'll have to be more
    precise about what you're doing.

     
  • Gabor Guta

    Gabor Guta - 2010-04-20

    Given the following trace listener:

    public class TestListener extends XSLTTraceListener {
    ...

    public void enter(InstructionInfo info, XPathContext context) {
    int type = info.getConstructType();
    System.err.println("Line: " + info.getLineNumber()
    + ", Column: " + info.getColumnNumber()
    + ", Type (const): " + instNames.get(type)
    + ", Type (id): " + type);
    }
    ...


    and the following XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="&lt;a class=" "="" href="http://www.w 3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform" version="2.0">

    <xsl:output method="text" encoding="UTF-8"/>

    <xsl:template match="/">
    <xsl:apply-templates select="database/table"/>
    </xsl:template>

    <xsl:preserve-space elements="*"/>

    <xsl:template match="table">

    <xsl:variable name="itemname" select="@name"/>

    SET QUOTED_IDENTIFIER OFF
    GO

    SET ANSI_NULLS OFF
    GO

    drop procedure .
    GO

    CREATE PROCEDURE sp_<xsl:value-of select="$itemname"/>
    ...


    It produce the following output:
    Line: 6, Column: 25, Type (const): XSL_TEMPLATE, Type (id): 181
    Line: 7, Column: 48, Type (const): XSL_APPLY_TEMPLATES, Type (id): 130
    Line: 7, Column: -1, Type (const): XPATH_IN_XSLT, Type (id): 2011
    Line: 12, Column: 29, Type (const): XSL_TEMPLATE, Type (id): 181
    Line: 14, Column: -1, Type (const): LET_EXPRESSION, Type (id): 2013
    Line: 14, Column: -1, Type (const): XPATH_IN_XSLT, Type (id): 2011
    Line: 12, Column: -1, Type (const): XSL_TEXT, Type (id): 182
    Line: 22, Column: 60, Type (const): XSL_VALUE_OF, Type (id): 184
    Line: 22, Column: -1, Type (const): XPATH_IN_XSLT, Type (id): 2011
    Line: 12, Column: -1, Type (const): XSL_TEXT, Type (id): 182
    Line: 25, Column: 55, Type (const): XSL_VALUE_OF, Type (id): 184
    ...


    Expected result in case of the first XSL_TEXT element:
    Line: 22, Column: 27, Type (const): XSL_TEXT, Type (id): 182
    Expected result in case of the second XSL_TEXT element:
    Line: 25, Column: 22, Type (const): XSL_TEXT, Type (id): 182

    Thank you for your help in advance!

     
  • Michael Kay

    Michael Kay - 2010-07-09

    Sorry for dropping the ball on this one.

    I see what you mean. The code is designed to use the line number of the
    preceding sibling element for a text node, but actually it's using the line
    number of the parent element. I'll commit another patch to fix that. I'm not
    intending to start maintaining the line number of the text node itself.