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


    Aug 4, 2011
    Likes Received:
    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="">

    the XSL I created as below:
    <?xml version="1.0"?>
    xmlns:xsl="" version="1.0"

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

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


    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="">

    but, actually the result is:
    <root xmlns:aa="">

    can any one help to indicate, how should I do, can get the expected result?
    abnerliu, Aug 4, 2011
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.