[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Commenting selected elements (parents) and keeping

Subject: RE: Commenting selected elements (parents) and keeping the child elements with attributes/restoring parents elements somewhere else
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 9 May 2008 09:09:34 +0100
RE:  Commenting selected elements (parents) and keeping
You're constructing a result tree, and in the tree model of XML, comments
can't contain elements, they can only contain text. So your only option is
to contruct a comment that contains text that looks (to an untrained
observer) like an element. That is, you need to serialize the elements by
hand - which you could perhaps do using saxon:serialize().

Another option, which only works if you know that the output of your
stylesheet is being serialized, is to generate the comment delimiters <!--
and --> as text using disable-output-escaping or character maps; you can
then generate the elements as real elements.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Pankaj Chaturvedi [mailto:pankaj.chaturvedi@xxxxxxxxx] 
> Sent: 09 May 2008 09:01
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Commenting selected elements (parents) and 
> keeping the child elements with attributes/restoring parents 
> elements somewhere else
> 
> 
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.