Re: [xsl] Need help with XSLT: adding new node btw existing elements

Subject: Re: [xsl] Need help with XSLT: adding new node btw existing elements
From: "Nishi Bhonsle" <nishiandprafull@xxxxxxxxx>
Date: Thu, 17 Aug 2006 12:27:19 -0700
On 8/17/06, David Carlisle <davidc@xxxxxxxxx> wrote:

> This sounds to me that you are using MSXML. Afaik, it is the only xslt > processor that adds xmlns="" to nodes that do not belong to a > namespace,

No, every processor would do this in this example, unless it has a bug.

David

So, is there no way using xslt to avoid the addition of xmlns=" " ? Apparently I cant use anything external like perl to remove this string later from the output xml file.

I also noticed that if i my input xml doc contains some additional
elements then they get skipped in the output xml doc using my existing
xslt. Can you please tell me what I am missing in my current xslt?
Thanks a lot!

<--Input xml doc -->
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="C:\test.xslt"?>
<test xmlns="blabla">
<comp id="Old">
<process-type id="ASG" module-id="TESTER1" status="enabled">
<environment>
<variable id="TMP" value="C:\DOCUME~1\manez\LOCALS~1\Temp"/>
</environment>
<start timeout="600"/>
<stop timeout="120"/>
</process-type>
</comp>
<comp id="New">
<process-type id="home" module-id="TESTER" status="enabled">
<module-data>
<category id="start-parameters">
</category>
<category id="stop-parameters">
</category>
</module-data>
<start timeout="600" retry="2"/>
<stop timeout="120"/>
<restart timeout="720" retry="2"/>
<process-set id="default_group" numprocs="1"/>
</process-type>
</comp>
</test>

<--XSLT -- >
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:b="blabla"
exclude-result-prefixes="b">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="b:process-type">
<xsl:if test="@id='ASG'">
<xsl:call-template name="copy"/>
</xsl:if>
<xsl:if test="@id='home'">
<process-type id="home" module-id="TESTER" status="enabled">
<environment>
<variable id="SAROOTDIR" value="D:\Dir1"/>   	             	
<variable id="SADATADIR" value="D:\Dir2"/> 	
</environment>
</process-type>   	
</xsl:if>
</xsl:template>
	
<-- INTERNAL TEMPLATES -->
<!-- create a root document, so the result is wellformed -->
<xsl:template match="/">
<filtered-data>
<xsl:apply-templates/>
</filtered-data>
</xsl:template>

<!-- copy one element with its attributes and apply templates for
nested elements -->
<xsl:template name="copy">
<xsl:copy>
<xsl:apply-templates select="@*" mode="copy" />
<xsl:apply-templates/>
<xsl:value-of select="text()"/>
</xsl:copy>
</xsl:template>

<!-- copy attributes -->
<xsl:template match="@*" mode="copy">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>


<--Output XML document --> <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="C:\test.xslt"?> <test xmlns="blabla"> <comp id="Old"> <process-type id="ASG" module-id="TESTER1" status="enabled"><environment> <variable id="TMP" value="C:\DOCUME~1\manez\LOCALS~1\Temp"/> </environment><start timeout="600"/><stop timeout="120"/></process-type> </comp> <comp id="New"> <process-type xmlns="" id="home" module-id="TESTER" status="enabled"> <environment xmlns=""> <variable xmlns="" id="SAROOTDIR" value="D:\Dir1"/> <variable xmlns="" id="SADATADIR" value="D:\Dir2"/> </environment> <!--THE OTHER ELEMENTS such as module-data DIDNOT GET PRINTED--> </process-type> </comp> </test>

Current Thread