Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

JDOM Document and Saxon DocumentWrapper

Help
guill
2004-10-12
2012-10-08
  • guill
    guill
    2004-10-12

    Hello,

    I have built a JDOM Document and am trying to apply an XSLT transform to it. It seems to me that Saxon requires me to instantiate a DocumentWrapper for which I need to specify a base URI for my Document. I am not really clear about the need for this param (couldn't find anything interesting through Google...) and whatever I set for it (which may be be stupid considering my lack of understanding of this param) ie null,"/","test",... I keep on getting an Exception :"URI is not absolute" at run-time...Could anybody point me to more info regarding this param and possibly to more details about how it should be set in the context of the DocumentWrapper ?
    Thank you for your help.
    Regards,
    G.

     
    • Michael Kay
      Michael Kay
      2004-10-13

      The purpose of supplying a base URI is so that relative URIs occurring within the document can be resolved. For example if the document contains <A href="thing.xml"> and the base URI is "file:///c:/mydocs/index.xml" then "thing.xml" will be interpreted as "file:///c:/mydocs/thing.xml". If you aren't using relative URIs then any absolute URI will do as the base URI, if you are, then it needs to be the correct URI to resolve these references.

      Michael Kay

       
    • guill
      guill
      2004-10-13

      Thx for your answer.

      I had done my homework meanwhile and figured out that the following could be used and was working fine :
      new DocumentWrapper(doc, "file://./mybasefolder");

      As a side note, if using SAXON8, this becomes :
      new DocumentWrapper(doc, "file://./mybasefolder",new Collection());

      Thx.
      G.

       
    • guill
      guill
      2004-10-14

      Actually...I still have a question related to this :- )
      In my case, the Document I am wrapping doesn't contain relative URIs. Instead, the XSLT I am applying to it does. Is there any mechanism of base URI transfer from the doc to the XSLT ? Because the base URI I set through the DocWrapper is my Doc not my XSLT doc...
      Thank you for your help.
      Regards,
      G.

       
      • Michael Kay
        Michael Kay
        2004-10-15

        I can't think of anything that would use the base URI other than things like the document() and base-uri() functions. If you are still getting errors because of the base URI, I need to know what the error message is and what the stylesheet looks like.

        Michael Kay

         
    • guill
      guill
      2004-10-15

      Sorry Mike if my question was not correctly formulated...

      My stylesheet does contain calls to document() with relative URIs (e.g. doc('../toto/titi.xml') ). So I understand that a base URI is necessary to be able to resolve these relative URIs included in my stylesheet.

      Before your answer, I believed that the base URI set for my source doc through the Wrapper was kind of transfered to my stylesheet in order for the mentioned relative URIs to be resolved. But, actually, even if I set the base URI for my Wrapper to file://anythingBecauseMyDocDoesntHaveRelativeURIs, everything works just fine, which makes sense from my source doc perpective.
      But my question becomes : how do the relative URIs included in my stylesheet get resolved ? I guess that, by default, the folder where the stylesheet is could be used. What if I would like to use any other base URI ? How would I set it ? There is no such Wrapper for the stylesheet...
      Thanks for your help.
      G.

       
      • Michael Kay
        Michael Kay
        2004-10-15

        First point: the document() function uses the base URI of the stylesheet if the URI is supplied as a string, but the base URI of the supplied node [typically the base URI of the source document] if the URI is supplied as a node.

        Second point: the base URI of the stylesheet is taken from the systemID supplied using setSystemId() on the Source object from which the JAXP Templates object is constructed. If you supply a File object, it will be the base URI of this file. You can always override it using Source.setSystemId(), or by including an xml:base attribute within the stylesheet itself.

        You can also write your own URIResolver if you want complete control over how URIs are dereferenced.

        Michael Kay

         
    • guill
      guill
      2004-10-15

      Thank you, Mike. This is really helpful.
      G.