> Hi,
>
> I need to copy all the child elements from the parent element to output
> xml using xalan c++ 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 c++ 1.10 , it does not copy.
>
> How I can achieve this using xalan c++ 1.10 ?
>
> 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
All namespace prefixes in your XML file should be namespace qualified.
<?xml version="1.0" encoding="UTF-8"?>
<SwInt:Request xmlns:SwInt="urn:swift:snl:ns.SwInt"
xmlns:SwInt1="urn:swift:snl:ns.SwInt1" >
<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>
The following is an edit of your xslt file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:SwInt="urn:swift:snl:ns.SwInt"
xmlns:SwInt1="urn:swift:snl:ns.SwInt1" >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:copy-of select="/SwInt:Request/SwInt:RequestHeader"/>
</xsl:template>
</xsl:stylesheet>
Producing the output file
<SwInt:RequestHeader xmlns:SwInt="urn:swift:snl:ns.SwInt"
xmlns:SwInt1="urn:swift:snl:ns.SwInt1">
<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>
I am unclear on what you are actually trying to do:
You only need in the stylesheet the prefix declarations used in the
stylesheet. The xml documents need namespace declarations for the
prefixes they use.
Steven J. Hathaway