xsl-list
[Top] [All Lists]

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

2008-05-09 01:10:02

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(_dot_)chaturvedi(_at_)idsil(_dot_)com] 
Sent: 09 May 2008 09:01
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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."

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--