XSLT - Add Namespace to Output

SilicaGel

New Member
I am trying to generate an XML output and i have created an XSLT that will do so. However the root node is is missing some Name spacing. How do you add Namespace to the root element of an XML structure. This it the XSLT i am using:XSLT\[code\]<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:doc="urn:sapcom:document:sap:rfc:functions" xmlns:r="http://www.castiron.com/response" exclude-result-prefixes="r"> <xsl:output method="xml" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:element name="imageScene7Request"> <xsl:element name="productIds"> <xsl:for-each select="r:productGetAllByIdsResponse/r:payload/r:products"> <xsl:value-of select="r:id"/> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:for-each> </xsl:element> </xsl:element> </xsl:template></xsl:stylesheet>\[/code\]The Namespacing i would like to add to the root \[code\]http://www.castiron.com/response\[/code\]INPUT XML\[code\]<?xml version="1.0" encoding="UTF-8"?><productGetAllByIdsResponse xmlns="http://www.castiron.com/response"> <rcode>0</rcode> <rmessage>Success</rmessage> <payload> <products> <id>4022280</id> </products> <products> <id>4022280</id> </products> </payload></productGetAllByIdsResponse>\[/code\]You will see that when you run this is gives you:\[code\]<?xml version="1.0" encoding="utf-8"?><imageScene7Request> <productIds>4022280,4022280</productIds></imageScene7Request>\[/code\]However i would like this:\[code\]<?xml version="1.0" encoding="utf-8"?><imageScene7Request xmlns="http://www.castiron.com/response"> <productIds>4022280,4022280</productIds></imageScene7Request>\[/code\]Reply @dbasemanThat worked however it then gave the second tag a null namespace, as shown below:\[code\]<?xml version="1.0" encoding="utf-8"?><imageScene7Request xmlns="http://www.castiron.com/response"> <productIds xmlns="">4022280,4022280</productIds></imageScene7Request>\[/code\]Is there a way to remove that?
 
Back
Top