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

Discussion in 'Software' started by abnerliu, Aug 4, 2011.

  1. abnerliu

    abnerliu

    Joined:
    Aug 4, 2011
    Messages:
    1
    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?
    abnerliu, Aug 4, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Omer Colakoglu
    Replies:
    1
    Views:
    405
    Somchai U.
    Aug 26, 2003
  2. Kendal Emery

    OT:: Namespace Miner

    Kendal Emery, Feb 12, 2004, in forum: MCSE
    Replies:
    11
    Views:
    1,967
    Rowdy Yates
    Feb 13, 2004
  3. CJ
    Replies:
    3
    Views:
    1,498
    Gerry Quinn
    Aug 4, 2006
  4. sgauthier
    Replies:
    3
    Views:
    2,339
  5. Anthony Curtis
    Replies:
    3
    Views:
    3,051
    Anthony Curtis
    Feb 16, 2011
Loading...

Share This Page