String liaisonClassName = System.getProperty("org.apache.xalan.source.liaison");
String liaisonClassName = m_liaison.getClass().getName();
  Stylesheet getStylesheetFromPIURL(String xslURLString, Node fragBase,                                    String xmlBaseIdent, boolean isRoot)    throws SAXException,    MalformedURLException,    FileNotFoundException,    IOException  {    StylesheetRoot m_stylesheetRoot = null;    Stylesheet stylesheet = null;    String[] stringHolder =    {      null};    xslURLString = xslURLString.trim();    int fragIndex = xslURLString.indexOf('#');    String fragID = null;    Document stylesheetDoc;    if(fragIndex == 0)    {      diag("Locating stylesheet from fragment identifier...");      fragID = xslURLString.substring(1);            // Try a bunch of really ugly stuff to find the fragment.      // What's the right way to do this?      // Create a XPath parser.      XPathParser parser = new XPathParser((ErrorListener)m_problemListener.getErrorHandler(), null);      XPathContext xpathContext = new XPathContext();      PrefixResolverDefault nsNode = new PrefixResolverDefault(fragBase); //xpathContext.getNamespaceContext();      NodeIterator nl = null;      // Create the XPath object.      try{      XPath xpath = new XPath(fragID, null, nsNode, XPath.MATCH);      Compiler compiler = new Compiler();      // Parse the xpath      parser.initXPath(compiler, "id("+fragID+")", nsNode);      org.apache.xpath.objects.XObject xobj = xpath.execute(xpathContext, fragBase, nsNode);      nl = xobj.nodeset();      if(nl.nextNode() == null)      {        // xobj = Stylesheet.evalXPathStr(getExecContext(), "//*[@id='"+fragID+"']", fragBase, nsNode);        // Create the XPath object.        xpath = new XPath(fragID, null, nsNode, XPath.MATCH);        // Parse the xpath        parser.initXPath(compiler, "//*[@id='"+fragID+"']", nsNode);        xobj = xpath.execute(xpathContext, fragBase, nsNode);        nl = xobj.nodeset();        if(nl.nextNode() == null)        {          // xobj = Stylesheet.evalXPathStr(getExecContext(), "//*[@name='"+fragID+"']", fragBase, nsNode);          // Create the XPath object.          xpath = new XPath(fragID, null, nsNode, XPath.MATCH);          // Parse the xpath          parser.initXPath(compiler, "//*[@name='"+fragID+"']", nsNode);          xobj = xpath.execute(xpathContext, fragBase, nsNode);          nl = xobj.nodeset();          if(nl.nextNode() == null)          {            // Well, hell, maybe it's an XPath...            // xobj = Stylesheet.evalXPathStr(getExecContext(), fragID, fragBase, nsNode);            // Create the XPath object.            //((StylesheetHandler)( m_processor.getTemplatesBuilder())).getLocator()            xpath = new XPath(fragID, null, nsNode, XPath.MATCH);            // Parse the xpath            parser.initXPath(compiler, fragID, nsNode);            xobj = xpath.execute(xpathContext, fragBase, nsNode);            nl = xobj.nodeset();          }        }      }      }      catch (TransformerException te)      {        throw new SAXException(te);      }      if(nl.nextNode() == null)      {        error(XSLTErrorResources.ER_COULDNT_FIND_FRAGMENT, new Object[] {fragID}); //"Could not find fragment: "+fragID);      }      // Use previous because the previous call moved the pointer.      // or should we use getRoot??      Node frag = nl.previousNode(); //.item(0);      if(Node.ELEMENT_NODE == frag.getNodeType())      {        pushTime(frag);        if(isRoot)        {          m_stylesheetRoot = createStylesheetRoot(stringHolder[0]);          stylesheet = m_stylesheetRoot.getObject();        }        else        {          //stylesheet = new Stylesheet(m_stylesheetRoot);          // stylesheet = ((StylesheetHandler)(m_processor.getTemplatesBuilder())).getStylesheetRoot();          try{            Source source = new XSLTInputSource(fragID).getSourceObject();             Templates templates = m_tfactory.newTemplates(source);            stylesheet = (org.apache.xalan.templates.StylesheetRoot)templates;          }          catch (TransformerConfigurationException tce)          {            throw new SAXException(tce);          }        }        addTraceListenersToStylesheet();        try{        StylesheetHandler stylesheetProcessor          = new StylesheetHandler((TransformerFactoryImpl)m_tfactory);                   stylesheetProcessor.pushStylesheet(stylesheet);        TreeWalker tw = new TreeWalker(stylesheetProcessor);        tw.traverse(frag);        displayDuration("Setup of "+xslURLString, frag);        }        catch (TransformerConfigurationException tce)        {          throw new SAXException(tce);        }      }      else      {        stylesheetDoc = null;        error(XSLTErrorResources.ER_NODE_NOT_ELEMENT, new Object[] {fragID}); //"Node pointed to by fragment identifier was not an element: "+fragID);      }    }    else    {      // TODO: Use Reader here??      // hmmm.. for now I'll rely on the XML parser to handle      // fragment URLs.      diag(XSLMessages.createMessage(XSLTErrorResources.WG_PARSING_AND_PREPARING, new Object[] {xslURLString})); //"========= Parsing and preparing "+xslURLString+" ==========");      pushTime(xslURLString);      if(isRoot)      {        m_stylesheetRoot = createStylesheetRoot(xslURLString);        stylesheet = m_stylesheetRoot.getObject();      }      else      {        stylesheet = new Stylesheet(m_stylesheetRoot.getObject());      }      addTraceListenersToStylesheet();      try{      org.apache.xalan.processor.StylesheetHandler stylesheetProcessor        = new StylesheetHandler((TransformerFactoryImpl)m_tfactory); //this, stylesheet);       stylesheetProcessor.pushStylesheet(stylesheet);         // new StylesheetHandler(this, stylesheet);      }      catch (TransformerConfigurationException tce)      {        throw new SAXException(tce);      }            URL xslURL = getURLFromString(xslURLString, xmlBaseIdent);      XSLTInputSource inputSource = new XSLTInputSource(xslURL.toString());      String liaisonClassName = System.getProperty("org.apache.xalan.source.liaison");      if(null != liaisonClassName)      {        try{          DOM2Helper liaison =  (DOM2Helper)(Class.forName(liaisonClassName).newInstance());          liaison.parse(SAXSource.sourceToInputSource(inputSource.getSourceObject()));        }        catch (ClassNotFoundException e1)         {          throw new SAXException("XML Liaison class " + liaisonClassName +            " specified but not found", e1);        }         catch (IllegalAccessException e2)         {          throw new SAXException("XML Liaison class " + liaisonClassName +            " found but cannot be loaded", e2);        }         catch (InstantiationException e3)         {          throw new SAXException("XML Liaison class " + liaisonClassName +            " loaded but cannot be instantiated (no empty public constructor?)",            e3);        }                catch (TransformerException tce)        {          throw new SAXException(tce);        }      }        //m_parserLiaison.setDocumentHandler(stylesheetProcessor);      //m_parserLiaison.parse(inputSource);      displayDuration("Parsing and init of "+xslURLString, xslURLString);    }    return stylesheet;  }