Re: Need to copy all child elements of a parent element

Nathan Nadeau <[email protected]> Mon, 07 Nov 2011 16:05:58 -0500
Newsgroups gmane.text.xml.xalan.java.user
Organization Gleim Publications
Message-ID <[email protected]>
Hi Ajay,

If the XML is valid, I don't see how you can have SwInt1 prefix without 
declaring the SwInt1 namespace in your source XML. That namespace prefix 
is being used in the XML, so it should be declared.

XSLT will of course complain about SwInt1 not being defined. Both Xalan 
and my version of Altova XMLSpy complain.

If you were to add a declaration of the SwInt1 namespace to the source 
XML, then the XSLT would work as expected.

Nathan

ajay bhadauria wrote:
> Hi,
>  
> I need to copy all the child elements from the parent element to 
> output xml using java transform method. However, one of the child 
> element is prefixed but does not have corresponding namespace.
>  
> What should I do in xslt so that all the children elements of parent 
> element are copied to output xml file without caring the namespace. 
> Altova XMLSpy does that but When I use xalan-java 2.7.1 , it does not 
> copy. 
>  
> How I can achieve with xalan java 2.7.1 ?
>  
> E.g.
> Input XML file
> ============
> <?xml version="1.0" encoding="UTF-8"?>
> <SwInt:Request >
>                 <SwInt:RequestHeader>
>                         
> <SwInt1:Requestor>cn=requestor,o=pimxbebb,o=swift1</SwInt1:Requestor>
>                         
> <SwInt:Responder>cn=responder,o=pimxus33,o=swift</SwInt:Responder>
>                         <SwInt:RequestRef>xyz</SwInt:RequestRef>
>                 </SwInt:RequestHeader>
> </SwInt:Request>
> XSLT file
> ======
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>    xmlns:Sw="urn:swift:snl:ns.Sw" xmlns:SwInt="urn:swift:snl:ns.SwInt" 
> xmlns:SwSec="urn:swift:snl:ns.SwSec" >
>         <xsl:output method="xml" version="1.0" encoding="UTF-8" 
> indent="yes"/>
>         <xsl:template match="/">
>                 <xsl:copy-of select="/SwInt:Request/SwInt:RequestHeader"/>
>         </xsl:template>
> </xsl:stylesheet>
> Output Xml comes with
> <?xml version="1.0" encoding="UTF-8"?>
>  
> Regards
> Ajay
>

-- 
Nathan Nadeau
[email protected]
Software Development
Gleim Publications, Inc.
http://www.gleim.com