You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Simon Kitching <si...@ecnetwork.co.nz> on 2002/08/14 07:00:47 UTC

xpath: user code broken between 2.3.1 and 2.4D1

Hi All,

I have a custom extension element which internally evaluates a "select"
attribute by calling XPath methods. Code which worked on xalan 2.3.1
does not work correctly after upgrading to xalan 2.4D1.

Basically, what happens is that my custom element gets passed an xpath
expression in its select attribute, just like <xsl:value-of> would. The
custom element evaluates the expression like <xsl:value-of> would, then
applies a whole bunch of extra validation rules according to other
attributes passed to the custom element (like min/max length,
wellformed-date-validation if it is a date, etc).

In Xalan2.3.1 it works fine. However in Xalan2.4D1, evaluation of any
xpath expression containing variable references fails because it cannot
find the variables.

The most likely place (from what I can see) for the cause of this change
is org/apache/xpath/XPath.java; 2.3.1 is based on version 1.22, while
2.4D1 is based on 1.24. A number of serious-looking changes appear to
have occurred to this file...

Any suggestions/help would be *greatly* appreciated; I tried upgrading
to see if it would resolve another problem I was having. And start of
UAT phase was last friday :-(

Attached are:
  * test xml and xsl files demonstrating the problem
  * complete source code for the custom extension element (1 file)
    The relevant methods for this problem are text, text_ and doSelect.
  * a compiled version of the custom element. Just adding this to the
    classpath should allow it to be invoked from the stylesheet.

This problem has been experienced on:
 * Red Hat 7.3 with sun java 1.4.x (using java's endorsed override to
   force use of xerces/xalan/xml-apis jars).
 * AIX 5.x with IBM's JVM version 1.3.1
 
The xsl file is:

<?xml version="1.0"?> 
<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:lxlst="http://xml.apache.org/xslt"
  
  xmlns:ecnfns="xalan://nz.co.ecnetwork.xsltmap"
  xmlns:ecnfld="http://www.ecnetwork.co.nz/xsltmap/extension"
  
  extension-element-prefixes="ecnfld"
  >
  
  <lxlst:component prefix="ecnfld">
    <lxlst:script lang="javaclass"
src="nz.co.ecnetwork.xsltmap.Extensions"/>
  </lxlst:component>
  
  <xsl:output method="text" encoding="ISO-8859-1"/>
  
<!-- ======================== -->
  <xsl:variable name="foo" select="'bar'" />

  
  <xsl:template match="/">
    <ecnfld:text select="$foo"/>
  </xsl:template>
</xsl:stylesheet>

The xml file is:

<root/>

And the critical bit of the java code which is called to evaluate the
select attribute of the <ecnfld:text> is:


    private static String doSelect(
    XSLProcessorContext procContext, 
    ElemExtensionCall extensionElement,
    String selectStr)
    throws TransformerException
    {
        String nodeText = "";
        if ((selectStr != null && selectStr.length() != 0))
        {
            TransformerImpl transformer = procContext.getTransformer();
            XPathContext xpContext = transformer.getXPathContext();

            try
            {
                int contextNode = xpContext.getContextNode();

                XPath dynamicXPath = new XPath(
                    selectStr,
                    xpContext.getSAXLocator(),
                    xpContext.getNamespaceContext(),
                    XPath.SELECT,
                    transformer.getErrorListener());

                XObject xobj1 = dynamicXPath.execute(
                                     xpContext, 
                                     contextNode,
                                     xpContext.getNamespaceContext());
                
                nodeText = xobj1.toString();
            }
            catch(TransformerException te)
            {
                String msg =
                    "failed to evaluate expression at line [" 
                    + xpContext.getSAXLocator().getLineNumber()
                    + "] : " + te.getMessage();
                
                reportError(procContext, extensionElement, msg);
                return "";
            }
        }

        return nodeText;
    }