संकलित नहीं कर सका मैं जावा में एक्सएसएलटी के साथ एक एक्सएमएल को बदलना चाहता हूं। इसके लिए मैं javax.xml.transform
पैकेज का उपयोग कर रहा हूं। हालांकि, मुझे अपवाद javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
मिलता है। यह वह कोड है जिसका मैं उपयोग कर रहा हूं:जावा ट्रांसफार्मर त्रुटि: स्टाइलशीट
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();
}
ध्यान दें कि मैंने अपवाद को फेंकने वाली रेखा को चिह्नित किया है।
जब मैं विधि में प्रवेश, 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.Transformer कॉन्फ़िगरेशन अपवाद' है। मैंने अपनी मूल पोस्ट संपादित की, अब यह है। – Ivan
आपका अंतिम टेम्पलेट खाली क्यों है? – Stephan