Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > Software > Transform self-define namespace XML with DOM, can't make value in the result Document

Reply
Thread Tools

Transform self-define namespace XML with DOM, can't make value in the result Document

 
 
abnerliu abnerliu is offline
Junior Member
Join Date: Aug 2011
Posts: 1
 
      08-04-2011
Hi All
I have an issue when using DOM to transform an XML with name space. I create an XSL to transform the XML, but when I using DOM to transform it, I found the result document has no value.
the sample XML I used as below:
<?xml version="1.0" encoding="UTF-8"?>
<aa:root xmlns:aa="http://www.aa.com/aa">
<aa:people>
<aa:name>apple</aa:name>
<aa:sex>male</aa:sex>
</aa:people>
</aa:root>

the XSL I created as below:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:aa="http://www.aa.com/aa">

<xsl:template match="/">
<root>
<xsl:call-template name="test"/>
</root>
</xsl:template>

<xsl:template name="test">
<hh>
<xsl:value-of select="/aa:root/aa:people/aa:sex/text()"/>
</hh>
</xsl:template>

</xsl:stylesheet>

and Java DOM codes I came up with as below:
public void transformWithDOM() throws Exception{
TransformerFactory factory = TransformerFactory.newInstance();
Templates translet = factory.newTemplates(new StreamSource(xslFile));

DOMSource source = null;
Transformer transformer = null;
DOMResult resultXmlDoc = null;

Document srcXmlDoc = getDocObj(strxml);

source = new DOMSource(srcXmlDoc);
resultXmlDoc = new DOMResult();
transformer = translet.newTransformer();
transformer.transform(source, resultXmlDoc);

Document outputDoc = (Document) resultXmlDoc.getNode();
}

the expected result should be:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:aa="http://www.aa.com/aa">
<hh>male</hh>
</root>

but, actually the result is:
<root xmlns:aa="http://www.aa.com/aa">
<hh/>
</root>

can any one help to indicate, how should I do, can get the expected result?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change to the public schema document for the XML namespace(xml.xsd) Henry S. Thompson XML 0 09-07-2005 01:58 PM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments