Quiero transformar un XML con XSLT en Java. Para eso estoy usando el paquete javax.xml.transform
. Sin embargo, obtengo la excepción javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
. Este es el código que estoy usando:Error de Java Transformer: no se pudo compilar la hoja de estilos
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();
}
Tenga en cuenta que he marcado la línea que arroja la excepción.
Cuando entro en el método, el valor de XSLTRule
es la siguiente:
<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>
¿Qué excepción captó? –
Es 'javax.xml.transform.TransformerConfigurationException'. Edité mi publicación original, está allí ahora. – Ivan
¿Por qué su última plantilla está vacía? – Stephan