xsl document() function - java SimpleTransform cannot find file

Discussion in 'Java' started by marty.gagnon@imagenow.com, Nov 28, 2006.

  1. Guest

    I have a xsl file that references a xml file using the document()
    function.

    I'm having trouble specifying the URI in the document() function of a
    xls stylesheet.

    I'm using java to transform the stylesheet, and when it evaluates the
    document() function, it cannot find the specified file.

    This is how I reference the xml file I'm having trouble with
    <xsl:value-of select="document('glcodes.xml',//)/glcodes/code"/>

    I'm using JRun as the web server and I get the following error

    SystemId Unknown; Line 1; Column -1; Can not load requested doc:
    C:\JRun4\bin\glcodes.xml (The system cannot find the file specified)

    I may understand what is going on. The document() function loads the
    file (in this case "glcodes.xml") relative to the xml file used when
    the xsl file is transformed. So in my below code, the "xmlSource" is
    loaded into memory and used. I guess since JRun is doing the
    transformation in memory the relative path is starting at the location
    where the Xalan processor has this file in memory which would be
    ...\JRun4\bin. The question is, how do I modify the URI in the
    document() fuction so it's relative to where the xml file is loaded
    from.

    javax.xml.transform.Transformer transformer =
    tFactory.newTransformer(xslSS);
    ByteArrayInputStream baais = new
    ByteArrayInputStream(xmlByteArray);
    BufferedInputStream biis = new BufferedInputStream(baais);
    StreamSource xmlSource = new StreamSource(biis);
    transformer.transform(xmlSource, result);

    Thanks
    Marty
    , Nov 28, 2006
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    >I have a xsl file that references a xml file using the document()
    > function.
    >
    > I'm having trouble specifying the URI in the document() function of a
    > xls stylesheet.
    >
    > I'm using java to transform the stylesheet, and when it evaluates the
    > document() function, it cannot find the specified file.
    >
    > This is how I reference the xml file I'm having trouble with
    > <xsl:value-of select="document('glcodes.xml',//)/glcodes/code"/>
    >
    > I'm using JRun as the web server and I get the following error
    >
    > SystemId Unknown; Line 1; Column -1; Can not load requested doc:
    > C:\JRun4\bin\glcodes.xml (The system cannot find the file specified)
    >
    > I may understand what is going on. The document() function loads the
    > file (in this case "glcodes.xml") relative to the xml file used when
    > the xsl file is transformed. So in my below code, the "xmlSource" is
    > loaded into memory and used. I guess since JRun is doing the
    > transformation in memory the relative path is starting at the location
    > where the Xalan processor has this file in memory which would be
    > ..\JRun4\bin.


    More likely, it's just using JRun's default directory .

    > The question is, how do I modify the URI in the
    > document() fuction so it's relative to where the xml file is loaded
    > from.


    Specify a URI resolver (Transformer.setURIResolver()) This should be called
    with the relative URI, which you can then translate to a Source using
    whatever logic is necessary. For instance, you can now find glcodes.xml as
    a Java resource instead of an external file, which may make packaging your
    application simpler.

    You'll probably want to start with getURIResolver(), so you can chain to any
    existing resolver for URLs you don't want to process yourself.
    Mike Schilling, Nov 29, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,591
    A. Bolmarcich
    May 27, 2005
  2. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help with XSL/XSL:FO for producing revision indicator bar in document.

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Apr 28, 2006, in forum: XML
    Replies:
    6
    Views:
    567
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    May 3, 2006
  3. Replies:
    1
    Views:
    406
    Joseph Kesselman
    Nov 28, 2006
  4. Mike
    Replies:
    0
    Views:
    390
  5. Cozmo
    Replies:
    5
    Views:
    2,561
    Dinis
    Mar 20, 2010
Loading...

Share This Page