2016-12-07 51 views
0

在xsl轉換中,我有一個包含其他xslt的xslt文件。問題是這些xslt的URI包含非法字符,特別是'##'。在XSLT看起來是這樣的:處理xslt包含中的非法URI字符

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

,當我嘗試實例化一個java Transformer我得到的錯誤:

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:#

這是java代碼:

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; 
} 

有沒有辦法用相對路徑代替絕對路徑?

謝謝

+1

您是否檢查包含##的真實路徑,是否意外修改? – amishra

+0

不幸的是,這是Unix文件系統上的真正路徑。它從客戶的版本控制系統給予應用程序WAR。 – koopa

回答

相關問題