You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Burkhardt Renz <Bu...@compuserve.com> on 2000/01/04 21:51:00 UTC

FuncLang.java

Hi !

The function FuncLang.java in the XPath package uses an algorithm which
stops
and returns true in case, the language id to test is found. But it
continues the
search with the ancestors if another language id is found. 

This is an example:
<root xml:lang="en">
  <child xml:lang="fr"> 
    lang("en")  is true! but should be false.
    lang("fr") also is true!

I propose the following change in FuncLang.java:

  public XObject execute(XPath path, XPathSupport execContext, Node
context, int opPos, Vector args) 
{    
    String lang = ((XObject)args.elementAt(0)).str();    Node parent =
context;
    while(null != parent)
    {
      if(Node.ELEMENT_NODE == parent.getNodeType())
      {
        String langVal = ((Element)parent).getAttribute("xml:lang");
        if(null != langVal)
        {
          if(langVal.toLowerCase().startsWith(lang.toLowerCase()))
          {
            int valLen = lang.length();
            if((langVal.length() == valLen) || (langVal.charAt(valLen) ==
'-'))
            {
>>here>> return path.m_true;
            }
          }
>>here>> return path.m_false;
        }
      }
      parent = execContext.getParentOfNode(parent);
    }
>>here>>return path.m_false;
  }

Or am I wrong?

BurkhardtRenz@compuserve.com