Reputation: 1530
How do I define the equivalent of the xpath-default-namespace, for example:
<xsl:stylesheet version="2.0" xpath-default-namespace="http://schemas.xmlsoap.org/soap/envelope/"
in the following Java code snippet for Saxon EE 9.5?
public String transform(String request) {
try {
ProfessionalConfiguration config = new ProfessionalConfiguration();
config.setExtensionElementNamespace("http://yeah.com", "com.MyFactory");
config.registerExtensionFunction(new MyVariable());
EnterpriseTransformerFactory factory = new EnterpriseTransformerFactory();
factory.setConfiguration(config);
Source xslt = new StreamSource(new File("text.xsl"));
Transformer transformer = factory.newTransformer(xslt);
Source input = new StreamSource(new File("test.xml"));
StringWriter result = new StringWriter();
transformer.transform(input, new StreamResult(result));
return result.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Upvotes: 0
Views: 420
Reputation: 163322
You can't change the default xpath namespace from your Java code, only from your XSLT code.
You say you can't edit the XSLT stylesheets but you can. They are XML documents and can be transformed, and you have a transformation language and transformation engine available to you. If there's no other way of solving this, transform the stylesheets before executing them.
Upvotes: 1