tags:

views:

75

answers:

3

hi i have a proble with xml and xslt i have one xml file with some comment i want to uncomment it example

<my-app>
 <name>
 </name>
  <!-- <class>
         <line></line>
   </class>-->
</my-app>

i want to uncomment this commented tag please help me in advance i am very new in xslt thanks in advance

+7  A: 
<!-- the identity template copies everything 
     (unless more specific templates apply) -->
<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>

<!-- this template matches comments and uncomments them -->
<xsl:template match="comment()">
  <xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>

Be aware that disable-output-escaping="yes" implies that the comment contents should be well-formed.

Tomalak
Nice! just learned something new. Thanks!
Roland Bouman
thanks allot for your,but i i could see one more problem like it will uncomment all the comment which i dont want so please help me here is the xml <my-app><!--using same --> <name> </name> <!-- <class> <line></line> </class>--></my-app>and expected result look like <my-app><!--using same --> <name> </name> <class> <line></line> </class></my-app>thanks in advance
vivek4075
Change `match="comment()"` to something like `match="comment()[contains(., '</')]"`. This makes it apply to comments only that look a bit like HTML. Not perfect, but maybe sufficient for this application.
Tomalak
A: 

thanks allot for your,but i could see one more problem like it will uncomment all the commented part which i dont want so please help me. here is the xml -->

and expected result look like

thanks in advance

vivek4075
A: 

i need to search the tags based on some condition like if inside the commented tag if somthing exist then uncomment the selected tag i am posting one dummy file others male --> my name vivek --> others female --> --> so i need to uncomment those tags which contains my name inside the tag so after xslt operation the file should look like others male --> my name vivek others female --> --> Thanks in advance

vivek4075