0

In a xsl transformation I have a xslt file that includes some other xslt. The problem is that the URI for these xslt contains illegal characters, in particular '##'. The xslt looks like this:

<xsl:include href="/appdm/tomcat/webapps/sentys##1.0.0/WEB-INF/classes/xslt/release_java/xslt/gen.xslt" />

and when I try to instantiate a java Transformer I get the error:

javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerConfigurationException: javax.xml.transform.TransformerException: org.xml.sax.SAXException: org.apache.xml.utils.URI$MalformedURIException: Fragment contains invalid character:#

This is the java code:

public String xslTransform2String(String sXml, String sXslt) throws Exception {
    String sResult = null;
    try {
        Source oStrSource = createStringSource(sXml);

        DocumentBuilderFactory oDocFactory = DocumentBuilderFactory.newInstance();
        oDocFactory.setNamespaceAware(true);

        //sXslt is the xslt content with the inclusions 
        //<xsl:include href="/appdm/tomcat/webapps/sentys##1.0.0/WEB-INF/classes/xslt/release_java/xslt/gen.xslt" />"
        Document oDocXslt = oDocFactory.newDocumentBuilder().parse(new InputSource(new StringReader(sXslt)));
        Source oXsltSource = new DOMSource(oDocXslt);

        StringWriter oStrOut = new StringWriter();
        Result oTransRes = createStringResult(oStrOut);
        Transformer oTrans = createXsltTransformer(oXsltSource);

        oTrans.transform(oStrSource, oTransRes);
        sResult = oStrOut.toString();
    } catch (Exception oEx) {
        throw new BddException(oEx, XmlProvider.ERR_XSLT, null);
    }
    return sResult;
}

private Transformer createXsltTransformer(Source oXsltSource) throws Exception {
    Transformer transformer = getXsltTransformerFactory().newTransformer(
            oXsltSource);
    ErrorListener errorListener = new DefaultErrorListener();
    transformer.setErrorListener(errorListener);

    return transformer;
}

is there a way I can go with relative paths instead of absolute path?

Thank you

Stefano Lazzaro
  • 387
  • 1
  • 4
  • 22

1 Answers1

1

To avoid the MalformedURIException, replace the second or both # with %23.

See https://stackoverflow.com/a/5007362/4092205

Community
  • 1
  • 1
Tony Graham
  • 7,306
  • 13
  • 20