1

i'm transforming a xml file A of xmlns="ans" via xslt 2.0 saxon in java with the javax.xml.Transformer into a xml file B of xmlns="bns".

When the transformation has performed the output xml shows only values of the xml file A and an error occurs:

[Fatal Error] :3:4: Content is not allowed in prolog.

When I delete the xmlns="ans" of file A, the result xml file b is correct and no errors while transforming occurs. For my use case the xml messages which will be transformed will contain a namespace. Any ideas how to solve that without deleting the namespace declaration of the input file?

Appendix:

My java code:

System.setProperty("javax.xml.transform.TransformerFactory",  
"net.sf.saxon.TransformerFactoryImpl");  

TransformerFactory transFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource("transformation.xsl");
Templates template = transFactory.newTemplates(stylesource);
Transformer transformer = template.newTransformer();
StreamSource source = new StreamSource(new File("filea.xml"));

StreamResult result = new StreamResult(new StringWriter());
transformer.transform(source, result);
//result will be written to fileb.xml

My filea.xml

<?xml version="1.0" encoding="UTF-8"?>
<message xmlns="ans">...
</message>

My transformation.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns="bns">
<xsl:output method="xml" indent="yes" />
...
</xsl>
1
  • Well duffymo, I did that before, but none of the first results fits my concrete case. I would assume that a person who is writing here tried google first. Commented Jun 23, 2011 at 12:56

1 Answer 1

2

Well unless you show us the stylesheet code processing elements we can only guess. I suspect putting the attribute xpath-default-namespace="ans" on your xsl:stylesheet element might fix the problem. If not then please post enough details of your code allowing us to reproduce the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mr. Honnen, that was all what was needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.