xsl-list
[Top] [All Lists]

RE: [xsl] JAXP: SAXResult.setSystemId()

2007-12-31 03:49:22
  I thought that the SAXResult.setSystemId(String) method set 
the System ID of the SAX events thrown by the transform.
But the following code displays the System ID of the
stylesheet:

JAXP is pretty unspecific about this. The description of
SAXResult.setSystemId() is "Set the systemID that may be used in association
with the ContentHandler." which tells you next to nothing. I think it is
best to regard the JAXP concept of "system ID" as representing the base URI
of nodes reported through the SAX interface.

Equally, the description of the Locator object in the SAX specification says
nothing about how the location should be set in the case of documents that
don't originate directly by parsing lexical XML. In Saxon, the Locator
passed to the ContentHandler for the result tree always reflects the
location in the stylesheet of the instruction that generated the element or
attribute in question. This information is used by debuggers and IDEs that
do back-mapping, and also by Saxon itself when you request schema-validation
of the result document.

Michael Kay
http://www.saxonica.com/



    public static void main(String[] args)
            throws TransformerException
    {
        // stylesheet and input sources
        Source style_src = ...;
        Source input = ...;

        // the stylesheet
        SAXTransformerFactory factory = new TransformerFactoryImpl();
        Templates style = factory.newTemplates(style_src);

        // the SAX handler
        ContentHandler handler = new DefaultHandler() {
            public void setDocumentLocator(Locator loc) {
                System.err.println(loc.getSystemId());
            }
        };

        // the result, encapsulating the handler
        SAXResult result = new SAXResult();
        result.setHandler(handler);
        result.setSystemId("http://sample.com/system-id";);

        // the transform
        style.newTransformer().transform(input, result);
    }

  Tested with Saxon 9.

  Did I mix up something?

  Regards,

--drkm






















      
______________________________________________________________
_______________
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails 
vers Yahoo! Mail http://mail.yahoo.fr


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>