xslt - Remove certain text between XML tags -


i need transform xml document:

<root> <tree> <leaf>hello</leaf> ignore me <pear>world</pear> </tree> </root> 

to this:

<root> <tree> <leaf>hello</leaf> <pear>world</pear> </tree> </root> 

the example simplified, basically, either remove instances of "ignore me" or that's not inside leaf or pear.

i've come xslt copies pretty everything:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">      <xsl:output method="xml" encoding="utf-8" standalone="yes"/>      <xsl:template match="root|tree">         <xsl:element name="{name()}">             <xsl:copy-of select="@*"/>             <xsl:apply-templates/>         </xsl:element>     </xsl:template>      <xsl:template match="leaf|pear">         <xsl:element name="{name()}">             <xsl:copy-of select="child::node()"/>         </xsl:element>     </xsl:template>  </xsl:stylesheet> 

what have found out how use xsl:call-template remove text inside leaf or pear element, didn't work things inside tree element.

thanks in advance.

looks identity transform looking for. because text direct child of root or tree should ignored add empty templates that. therefore try:

<xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/xsl/transform" >      <xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes" />      <xsl:template match="@*|node()">         <xsl:copy>             <xsl:apply-templates select="@*|node()"/>         </xsl:copy>     </xsl:template>     <xsl:template match="tree/text()" />     <xsl:template match="root/text()" />  </xsl:stylesheet> 

which generate following output:

<root>   <tree>     <leaf>hello</leaf>     <pear>world</pear>   </tree> </root> 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -