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 Bjoern Metzdorf <bm...@turtle-entertainment.de> on 2002/10/29 21:14:28 UTC

stylesheet uri in processing instruction

Hi,

I have a servlet which transforms an xmlstring using a xsltc precompiled
stylesheet class. This basically is working fine.

Problem:

I need to get the name of the stylesheet that is to be used for calling the
right precompiled stylesheet class.
I therefore added the processing instruction

<?xml-stylesheet href="/path/to/my/sheet.xsl" type="text/xsl"?>

to my xmlstring.

How do I efficiently get this sheetURI?

I tried the Transformerfactory.getAssociatedStylesheet method, but I don't
know how to convert the resulting Source object to a string. Besides this I
don't want to parse my xmlstring twice.

I assume I have to use a different contenthandler for my
parser.getXMLReader(), but I don't know how to do that :)

I am using this method for parsing:

-------------------- snip --------------------------
  private DTDMonitor _dtdMonitor = null;
  private DOMImpl getDOM(String xmlstring) {
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      factory.setFeature(Constants.NAMESPACE_FEATURE, true);
    }
    catch (Exception e) {
      factory.setNamespaceAware(true);
    }
    final DOMImpl dom = new DOMImpl();
    XMLReader reader = null;
    SAXParser parser = null;
    _dtdMonitor = new DTDMonitor();

    try {
  parser = factory.newSAXParser();
  reader = parser.getXMLReader();
  reader.setContentHandler(dom.getBuilder());
  _dtdMonitor.handleDTD(reader);
  reader.parse(new InputSource( new StringReader(xmlstring) ) );
    }
    catch (ParserConfigurationException e) {
      System.err.println("SAX Parser is not configured properly.\n"+
                          e.getMessage());
      System.exit(1);
    }
    catch (SAXException e ) {
      System.err.println("SAX Parser could not be created.\n"+
                          e.getMessage());
      System.exit(1);
    }
    catch (IOException e ) {
      System.err.println("XML Reader could not read xml document '"+
                          xmlstring + "'," + e.getMessage());
      System.exit(1);
    }

    return dom;
  }

-------------------- snap --------------------------


Please elaborate on a possible solution, as I am very new to java.

Thanks in advance.

Regards,
Bjoern