Java에서 XSLT로 XML을 변환하려고합니다. 이를 위해 javax.xml.transform
패키지를 사용하고 있습니다. 그러나 예외는 javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
입니다. 이것은 내가 사용하고있는 코드입니다 :Java Transformer 오류 : 스타일 시트를 컴파일 할 수 없습니다.
public static String transform(String XML, String XSLTRule) throws TransformerException {
Source xmlInput = new StreamSource(XML);
Source xslInput = new StreamSource(XSLTRule);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xslInput); // this is the line that throws the exception
Result result = new StreamResult();
transformer.transform(xmlInput, result);
return result.toString();
}
나는 예외를 throw하는 선을 표시했습니다. 내가 방법을 입력하면
는 XSLTRule
의 값은 이것이다 :
<xsl:stylesheet version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:msxsl='urn:schemas-microsoft-com:xslt'
exclude-result-prefixes='msxsl'
xmlns:ns='http://www.ibm.com/wsla'>
<xsl:strip-space elements='*'/>
<xsl:output method='xml' indent='yes'/>
<xsl:template match='@* | node()'>
<xsl:copy>
<xsl:apply-templates select='@* | node()'/>
</xsl:copy>
</xsl:template>
<xsl:template match="/ns:SLA
/ns:ServiceDefinition
/ns:WSDLSOAPOperation
/ns:SLAParameter[@name='Performance']"/>
</xsl:stylesheet>
예외는 무엇입니까? –
이것은'javax.xml.transform.TransformerConfigurationException'입니다. 나는 원래의 글을 편집했는데, 지금 거기에있다. – Ivan
마지막 템플릿이 비어있는 이유는 무엇입니까? – Stephan