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 ext2 <xu...@tongtech.com> on 2011/06/04 07:07:28 UTC

a question of DOMSource

Hi:

When I using Xalan 2.7.1 to transform a DOM Source;

I find that:The Node combine with DOMSource must be a Document and It cannot
be just a Element; 

Does anyone know if this limit is correctly or wrong, and why?

 

Following is a simple program to illustrate it

 

Document doc = DocumentBuilder.parse(.)

 

//if I using document as input, the result is correct;

Transformer.transform(new DOMSource(doc), streamResult);

 

//but if I using element as input, the result is wrong;

Transformer.transform(new DOMSource(doc.getDocumentElement), streamResult);

 

 

Ps: xml  xslt I used:

Xml:

 

<?xml version="1.0" encoding="UTF-8"?>

<Record xmlns="http://www.tongtech.com/tiwen/record1">

<content1>a</content1>

<content2>b</content2>

<content3>c</content3>

</Record>

 

Xslt:

It's too long, but it logical is very simple, just exchange field content2 &
content 3; 

And I am sure it's correctly, because I have use a StreamSource(xml-stream),
and Document 's DOMSource as input, their result both are correctly;

but if anyone interest with it, I can post it in reply;

 

 

 

 

 


Re: a question of DOMSource

Posted by Christoffer Dam Bruun <cd...@flyingpigs.dk>.
Hi,

If your xpath expressions starts with '/'  e.g. '/Records/Record' then 
you need a document  If you are
transforming a "sub" element you cannot start with '/' e.g. '/Record' 
but must use 'Record'

Best regards
Christoffer Bruun

On 04-06-2011 07:07, ext2 wrote:
>
> Hi:
>
> When I using Xalan 2.7.1 to transform a DOM Source;
>
> I find that:The Node combine with DOMSource must be a Document and It 
> cannot be just a Element;
>
> Does anyone know if this limit is correctly or wrong, and why?
>
> Following is a simple program to illustrate it
>
> Document doc = DocumentBuilder.parse(...)
>
> //if I using document as input, the result is correct;
>
> Transformer.transform(new DOMSource(doc), streamResult);
>
> //but if I using element as input, the result is wrong;
>
> Transformer.transform(new DOMSource(doc.getDocumentElement), 
> streamResult);
>
> Ps: xml  xslt I used:
>
> Xml:
>
> <?_xml_ version="1.0" encoding="UTF-8"?>
>
> <Record _xmlns_="http://www.tongtech.com/tiwen/record1">
>
> <content1>a</content1>
>
> <content2>b</content2>
>
> <content3>c</content3>
>
> </Record>
>
> Xslt:
>
> It's too long, but it logical is very simple, just exchange field 
> content2 & content 3;
>
> And I am sure it's correctly, because I have use a 
> StreamSource(xml-stream), and Document 's DOMSource as input, their 
> result both are correctly;
>
> but if anyone interest with it, I can post it in reply;
>