How to use catalog.xml in document() function

Help
Jack Bush
2010-07-26
2012-10-08
  • Jack Bush
    Jack Bush
    2010-07-26

    Hi Forum members,

    I am encountering an issue in Saxon 9.1 XSLT 2.0 stylesheet when trying to
    open secondary xhtml documents (using document() function) generated from
    TagSoup parser which included the following DTD entity reference:

    The data that I need is in the xhtml document already and the lookup of DTD
    has been more of a nuisance in this case. As a result, I am wondering whether
    the following steps could be achieved:

    ( i ) How to direct the document() function in masterdox1.xsl stylesheet to
    use catalog.xml to lookup local a copy of DTD instead.

    Please refer to the original issue
    http://www.biglist.com/lists/lists.mulberrytech.com/xsl-
    list/archives/201007/msg00094.html
    which has been partly
    resolved using catalog.xml when looking up the main source in Java as follows:

    // Convert State HTML to XML format
    SAXBuilder stateSaxBuilder = new SAXBuilder("org.ccil.cowan.tagsoup.Parser",
    false);
    org.jdom.Document xhtmlmainjdomDocument = saxBuilder.build(originalHTMLFILE);

    .....
    Transformer transformer = TransformerFactory.newTransformer(new
    StreamSource(masterdox1.xsl));

    JDOMSource source = new JDOMSource(xhtmlmainjdomDocument);
    JDOMResult result = new JDOMResult();

    transformer.transform(source, result); // breaks on line 17 below in
    masterdox1.xsl when trying to read additional xhtml docs
    ....

    The snippet of masterdox1.xsl is as follows:

    8 <xsl:template match="/">
    9 <html>
    10 <head>
    11 <xsl:value-of select="/report/title"/>
    12 </head>
    13 <body style="font-family: sans-serif;">
    14

    Selected Purchase Orders - Unsorted


    15 <xsl:for-each select="/report/po">
    16 <xsl:apply-templates<br>17 select="**document(@filename)/purchase-order**"/>
    18 </xsl:for-each>
    19 </body>
    20 </html>
    21 </xsl:template>
    ....

    Any assistance would be much appreciated.

    Thanks,

    Jack

     
  • Michael Kay
    Michael Kay
    2010-07-26

    The basic answer is here:

    http://xml.apache.org/commons/components/resolver/resolver-
    article.html

    except that it's written in terms of using the command line rather than the
    JAXP API. It describes it like this:

    Similarly, Saxon supports command-line access to the resolvers:
    -x org.apache.xml.resolver.tools.ResolvingXMLReader
    -y org.apache.xml.resolver.tools.ResolvingXMLReader
    -r org.apache.xml.resolver.tools.CatalogResolver

    The -x class is used to read source documents, the -y class is used to read
    stylesheets.

    The one that's important in your case (resolving the reference to a DTD held
    in the source document) is the -x option, which selects an XML parser
    preconfigured to use an EntityResolver that uses the catalog. The equivalent
    option using the JAXP API is

    factory.setAttribute("http://saxon.sf.net/feature/sourceParserClass",
    "org.apache.xml.resolver.tools.ResolvingXMLReader")

     
  • Jack Bush
    Jack Bush
    2010-07-26

    Hi Michael,

    Yes, perfect! Everything is working at last.
    Word cannot explain how elated I feel finally after beating around the bush
    for so long.

    This couldn't have been achieved without your help.

    Thank you very much once again,
    Jack