[xsl] Commenting selected elements (parents) and keeping the child elements with attributes/restoring parents elements somewhere else

Subject: [xsl] Commenting selected elements (parents) and keeping the child elements with attributes/restoring parents elements somewhere else
From: "Pankaj Chaturvedi" <pankaj.chaturvedi@xxxxxxxxx>
Date: Fri, 9 May 2008 13:31:09 +0530
Hello all,

Is there is a way to commenting some specific elements mostly parents while
retaining the child elements in output. I know I am sounding bit stupid as
far as the hierarchy of xml is concerns, but I need to restore the
parents/grand parents (instead omitting them) along with their attribute
values.


As of now I am trying the following, but its omit them.



	<xsl:template match="root">
<xsl:copy>
<xsl:attribute name="dummy">the_root</xsl:attribute>
			<xsl:apply-templates/>
			<xsl:apply-templates select=".//aaa"/>
	</xsl:copy>
	</xsl:template>


	<xsl:template match="root//aaa">
      <xsl:copy>
		<xsl:attribute name="dummy">xxx</xsl:attribute>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
	</xsl:copy>
	</xsl:template>


  <!-- omit these -->

 <xsl:template match="abc | bbb"/>




Input
====
<root>
	<abc id="123">
		<bbb>
			<aaa id="123">xxxxxx</aaa>
		</bbb>
		<abc>
</root>


Output
======

<root>
<!--<abc id="123"><bbb>-->
			<aaa id="123">xxxxxx</aaa>
<!--</bbb>
		<abc>-->

</root>

or may be something like
===================

<root>
			<aaa id="123">xxxxxx</aaa>

	<!--<abc id="123">
<bbb>--><!--</bbb>
<abc>-->

</root>


I've also tried to use the following but takes only text nodes of the <abc>
and <bbb> and "not their markup".

	<xsl:template match="root">
<xsl:copy>
<xsl:attribute name="dummy">the_root</xsl:attribute>

			<xsl:apply-templates/>
			<xsl:apply-templates select=".//aaa"/>
			<xsl:comment>
			<xsl:apply-templates select="./abc | .//bbb"/>
			</xsl:comment>
</xsl:copy>
	</xsl:template>



Hope I've made myself clear and any ideas in this regard will be highly
appreciated.


Best,

Pankaj Chaturvedi

============================================================================
================


Confidentiality Notice:" This message and any attachment(s)
contained here are information that is confidential, proprietary to
IDS Infotech Ltd. and its customers.
Contents may be privileged or otherwise protected by law. The
information is solely intended for the individual or the entity it
is addressed to. If you are not the intended recipient of this
message, you are not authorized to read, forward, print, retain,
copy or disseminate this message or any part of it. If you have
received this e-mail in error, please notify the sender immediately
by return e-mail and delete it from your computer."

Current Thread