You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Ryan,Peter (Contractor)" <Pe...@cna.com> on 2008/01/18 23:17:01 UTC
Transformer Loses XML Tags On Output
I am having an issue with output of data when I perform a
transformation.
I am attempting to do a DOMSource to DOMResult transformation. My
stylesheet has the xml:output property set to "xml".
Currently when that runs I get a DOMException:
javax.xml.transform.TransformerException: org.w3c.dom.DOMException:
HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is
not permitted.
This led me to think there was something wrong with the output which I
discovered by changing to a StreamSource and dumping to System.out:
<?xml version="1.0" encoding="UTF-8"?>fieldValue fieldValue2 ...
I would think I had something wrong with my stylesheet but I have two
reasons that make me think I have a xalan configuration error some
obscure defect.
1) The output of fieldValue fieldValue2 comes from my stylesheet which
should be wrapped in XML elements.
2) When I run the same code using SAXON 6.5.5 I get the output I am
expecting, eg:
<?xml version="1.0"
encoding="UTF-8"?<root><firstElement>fieldValue</firstElement></secondEl
ement>fieldValue2</secondElement>...
My transformer code is completely standard:
public Document transform(Document document) {
Source requestSource = new DOMSource(document);
URL url = this.getClass()getResource("stylesheet.xsl");
Source stylesheet = new StreamSource(url.toString());
Transformer transformer =
TransformerFactory.newInstance().newTransformer(stylesheet);
Document resultDocument =
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
transformer.transform(requestSource, new DOMResult(resultDocument));
Return resultDocument;
}
I have done exhaustive digging into this and am at a complete loss. It
seems like Xalan is using the text output method but I have explicitly
named the xml method type. Does anyone have any idea what would cause
Xalan to behave in this way?
Thank you in advance for your help.
Peter
E-MAIL CONFIDENTIALITY NOTICE: The contents of this e-mail message and any attachments are intended solely for the
addressee(s) and may contain confidential and/or legally privileged information. If you are not the
intended recipient of this message or if this message has been addressed to you in error, please
immediately alert the sender by reply e-mail and then delete this message and any attachments. If you
are not the intended recipient, you are notified that any use, dissemination, distribution, copying, or
storage of this message or any attachment is strictly prohibited.
Re: Transformer Loses XML Tags On Output
Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Peter.
"Ryan,Peter (Contractor)" <Pe...@cna.com> wrote on 2008-01-18
05:17:01 PM:
> I am having an issue with output of data when I perform a
> transformation.
>
> I am attempting to do a DOMSource to DOMResult transformation. My
> stylesheet has the xml:output property set to "xml".
>
> Currently when that runs I get a DOMException:
>
> javax.xml.transform.TransformerException: org.w3c.dom.DOMException:
> HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is
> not permitted.
>
> This led me to think there was something wrong with the output which I
> discovered by changing to a StreamSource and dumping to System.out:
>
> <?xml version="1.0" encoding="UTF-8"?>fieldValue fieldValue2 ...
>
> I would think I had something wrong with my stylesheet but I have two
> reasons that make me think I have a xalan configuration error some
> obscure defect.
>
> 1) The output of fieldValue fieldValue2 comes from my stylesheet which
> should be wrapped in XML elements.
>
> 2) When I run the same code using SAXON 6.5.5 I get the output I am
> expecting, eg:
>
> <?xml version="1.0"
> encoding="UTF-8"?<root><firstElement>fieldValue</firstElement></secondEl
> ement>fieldValue2</secondElement>...
>
> My transformer code is completely standard:
>
> public Document transform(Document document) {
> Source requestSource = new DOMSource(document);
> URL url = this.getClass()getResource("stylesheet.xsl");
> Source stylesheet = new StreamSource(url.toString());
> Transformer transformer =
> TransformerFactory.newInstance().newTransformer(stylesheet);
> Document resultDocument =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
> transformer.transform(requestSource, new DOMResult(resultDocument));
> Return resultDocument;
> }
>
> I have done exhaustive digging into this and am at a complete loss. It
> seems like Xalan is using the text output method but I have explicitly
> named the xml method type. Does anyone have any idea what would cause
> Xalan to behave in this way?
Could I ask you to provide a complete, stand-alone stylesheet, input
document and Java driver program that demonstrates the problem?
Thanks,
Henry
------------------------------------------------------------------
Henry Zongaro XSLT Processors Development
IBM SWS Toronto Lab T/L 313-6044; Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com