Jump to content

xmlns="" is getting added to element, while transforming one xml to another


Recommended Posts

Hi,I am using XSLT to transform one xml to another xml. During this for certain elements with name space an extra attribute xmlns="" is getting added.

The final resulting xml<ct:Name xmlns="">asd</ct:Name>   <ct:File xmlns="">asas</ct:File> 

How can this be removed. Can anybody help me with this?

Link to post
Share on other sites

This often happens with xsl:copy-of elements. They are made so that they preserve the namespace of whatever they are copying. If you place the source in the same namespace as the output, this will be removed.The other way (if edition on the source is not a viable option) is to match the element and create another element with the same local name, thus avoiding namespace copying.If you need any more details about that thouh, I'll need to see the XSLT and a sample XML for it.

Link to post
Share on other sites

I am providing the code as below.SOurce

<ApplicationDescMetaSchema xsi:noNamespaceSchemaLocation="applicationdescmetaschema.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">	<ApplicationDescriptions>			<SimpleApplicationDescription>			<SimpleApplicationDesc>				<Acronym>BU</Acronym>							<Attribute>					<Name>as</Name>				</Attribute>			</SimpleApplicationDesc>		</SimpleApplicationDescription>	</ApplicationDescriptions><ApplicationDescriptions>				<Attribute>			<Attributes>				<TypeName>asd</TypeName>				<TypeFile>asas</TypeFile>			</Attributes>		</Attribute>	</ApplicationDescriptions></ApplicationDescMetaSchema>

xslt

<xsl:stylesheet version="2.0" xmlns="urn:alcatel:upp-adl:2005-06" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ifc="http://3gpp/gup/ns/dataelement/IFC" xmlns:ct="http://3gpp/gup/ns/common/common-types" xmlns:amt="http://3gpp/gup/ns/common/application-model-types"><xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" name="xml"/>   <xsl:template match="/">   <xsl:element name="ApplicationsDescription">	  <xsl:element name="SimpleApplicationDescription">		 <xsl:element name="Acronym">	<xsl:value-of select="/ApplicationDescMetaSchema/ApplicationDescriptions/SimpleApplicationDescription/SimpleApplicationDesc[Acronym=$acronym]/Acronym"/>		 </xsl:element>		 <xsl:if test="exists(/ApplicationDescMetaSchema/ApplicationDescriptions/SimpleApplicationDescription/SimpleApplicationDesc[Acronym=$acronym]/Attribute)">	<xsl:for-each select="/ApplicationDescMetaSchema/ApplicationDescriptions/SimpleApplicationDescription/SimpleApplicationDesc[Acronym=$acronym]/Attribute">		<xsl:variable name="attribute" select="Name"/>		<xsl:element name="Attribute">										 <xsl:element name="Type">						   <xsl:element name="ct:Name">					  <xsl:value-of select="/ApplicationDescMetaSchema/ApplicationDescriptions/Attribute/Attributes[Name=$attribute]/TypeName"/>				</xsl:element>				<xsl:element name="ct:File">					   <xsl:value-of select="/ApplicationDescMetaSchema/ApplicationDescriptions/Attribute/Attributes[Name=$attribute]/TypeFile"/>							</xsl:element>				 </xsl:element>							  </xsl:element>				</xsl:for-each>			</xsl:if>		  </xsl:element>		 </xsl:element></xsl:template></xsl:stylesheet>

These are the code, can you tell me what can be done to remove that xmlns, because of this I am not able to use the xml generatedThank You

Link to post
Share on other sites

I don't see any empty "xmlns" in the output. Not with SAXON 8.9.0.3 at least. What processor are you using?Considering the fact that you use an XSLT 2.0 stylesheet, you'll need SAXON, or at least AltovaXML.Here's the output I get after adding the missing $acronym variable with a value of "BU":

<?xml version='1.0' ?><ApplicationsDescription xmlns="urn:alcatel:upp-adl:2005-06">  <SimpleApplicationDescription>	<Acronym>BU</Acronym>	<Attribute>	  <Type>		<ct:Name xmlns:ct="http://3gpp/gup/ns/common/common-types"/>		<ct:File xmlns:ct="http://3gpp/gup/ns/common/common-types"/>	  </Type>	</Attribute>  </SimpleApplicationDescription></ApplicationsDescription>

Seems perfectly fine to me. Because you use a namespace prefix that was never declared at the top level, the declaration is automatically added on that element to ensure the output is well formed. If you want, you could remove the prefix from the <xsl:element name="ct:Name"> and <xsl:element name="ct:File"> elements, but then those elements will be in the "urn:alcatel:upp-adl:2005-06" namespace, instead of the "http://3gpp/gup/ns/common/common-types" namespace.By the way, your stylesheet degrades very weird when used with XSLT 1.0 processor (MSXML 6.0 in my case):

<?xml version="1.0" encoding="UTF-8"?><ApplicationsDescription xmlns="urn:alcatel:upp-adl:2005-06"><SimpleApplicationDescription><Acronym>BU</Acronym>

I think it's because of the exists() function. It's XSLT 2.0 only. In XSLT 1.0 (and in XSLT 2.0!) you can test if a node exists by just specifiying the path to it (i.e. what you have as exists()'s argument).

Link to post
Share on other sites
I don't see any empty "xmlns" in the output. Not with SAXON 8.9.0.3 at least. What processor are you using?Considering the fact that you use an XSLT 2.0 stylesheet, you'll need SAXON, or at least AltovaXML.Here's the output I get after adding the missing $acronym variable with a value of "BU":
<?xml version='1.0' ?><ApplicationsDescription xmlns="urn:alcatel:upp-adl:2005-06">  <SimpleApplicationDescription>	<Acronym>BU</Acronym>	<Attribute>	  <Type>		<ct:Name xmlns:ct="http://3gpp/gup/ns/common/common-types"/>		<ct:File xmlns:ct="http://3gpp/gup/ns/common/common-types"/>	  </Type>	</Attribute>  </SimpleApplicationDescription></ApplicationsDescription>

Seems perfectly fine to me. Because you use a namespace prefix that was never declared at the top level, the declaration is automatically added on that element to ensure the output is well formed. If you want, you could remove the prefix from the <xsl:element name="ct:Name"> and <xsl:element name="ct:File"> elements, but then those elements will be in the "urn:alcatel:upp-adl:2005-06" namespace, instead of the "http://3gpp/gup/ns/common/common-types" namespace.By the way, your stylesheet degrades very weird when used with XSLT 1.0 processor (MSXML 6.0 in my case):

<?xml version="1.0" encoding="UTF-8"?><ApplicationsDescription xmlns="urn:alcatel:upp-adl:2005-06"><SimpleApplicationDescription><Acronym>BU</Acronym>

I think it's because of the exists() function. It's XSLT 2.0 only. In XSLT 1.0 (and in XSLT 2.0!) you can test if a node exists by just specifiying the path to it (i.e. what you have as exists()'s argument).

Thank You.I think the problem is with the processor I am using.I am not using Altova xmlspy, instead Authentic, which is creating this problem
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...