[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] copy nodes based on the criteria
Subject: Re: [xsl] copy nodes based on the criteria From: "Senthil Nathan" <rsennat@xxxxxxxxx> Date: Sat, 8 Dec 2007 00:39:23 +0530 |
Hi Mukul, Thanks. Thats works fine, I guess. So, first copy all the elements which has attributes, then drop elements which don't have the attribute Apply=1. Also dont drop the ancestor and descendant of elements with Apply=1 Thanks again Senthil > > On Dec 7, 2007 10:39 PM, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote: > > > Hi Senthil, > > Please try this ... > > > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > version=" 1.0"> > > > > <xsl:output indent="yes" /> > > > > <xsl:template match="@* | node()"> > > <xsl:copy> > > <xsl:apply-templates select="@*|node()"/> > > </xsl:copy> > > </xsl:template> > > > > <xsl:template match="*[not(@Apply = '1')][not(ancestor::*[@Apply = > > '1'] or descendant::*[@Apply = '1'])]" /> > > > > </xsl:stylesheet> > > > > This stylesheet uses the identity template, plus a template for > > excluding the desired elements. > > > > > > > > > > On 12/7/07, Senthil Nathan <rsennat@xxxxxxxxx > wrote: > > > Hi, > > > Long time back I posted this and got a solution too. But I have some > > > issues with that. I have also given that XSL below, which I got from this > > > forum earlier. > > > > > > Suppose orig.xml is as below, > > > <Root> > > > <Parent> > > > <Child1 Apply="1"> > > > <Value>100</Value> > > > </Child1> > > > </Parent> > > > <sub1> > > > <Parent> > > > <a> > > > <value>5000</value> > > > </a> > > > <a Apply="1"> > > > <value>3000</value> > > > </a> > > > <a Apply="7"> > > > <value>7000</value> > > > </a> > > > </Parent> > > > </sub1> > > > <noParent Apply="1"> > > > <value>1234</value> > > > </noParent> > > > <noParent Apply="10"> > > > <value>1234</value> > > > </noParent> > > > </Root> > > > > > > > > > -->new.xml should be as, > > > <Root> > > > <Parent> > > > <Child1 Apply="1"> > > > <Value>100</Value> > > > </Child1> > > > </Parent> > > > <sub1> > > > <Parent> > > > <a Apply="1"> > > > <value>3000</value> > > > </a> > > > > > > </Parent> > > > </sub1> > > > <noParent Apply="1"> > > > <value>1234</value> > > > </noParent> > > > </Root> > > > > > > XSL-----> > > > <?xml version=" 1.0" encoding="UTF-8" ?> > > > <xsl:stylesheet version="1.0" > > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform " > > > xmlns:x="http://www.w3.org/1999/xhtml" > > > xmlns:exslt="http://exslt.org/common " > > > xmlns:str="http://exslt.org/strings" > > > xmlns="http://www.w3.org/1999/xhtml " exclude-result-prefixes="x"> > > > > > > <xsl:template match="/"> > > > <xsl:comment>Matched root node template</xsl:comment> > > > <xsl:apply-templates /> > > > </xsl:template> > > > > > > <xsl:template match="//*[not(@Apply)]"> > > > <xsl:comment>Matched "element without Apply attribute" template</xsl:comment> > > > <xsl:copy> > > > <xsl:copy-of select="@*" /> > > > <xsl:apply-templates /> > > > </xsl:copy> > > > </xsl:template> > > > > > > <xsl:template priority="2.0" match="//*[@Apply='1']"> > > > <xsl:comment>Matched "element with Apply attribute = 1" > > > template</xsl:comment> > > > <xsl:copy> > > > <xsl:copy-of select="@*" /> > > > <xsl:apply-templates /> > > > </xsl:copy> > > > </xsl:template> > > > > > > <xsl:template match="//*[@Apply]"> > > > <xsl:comment>Matched "element with Apply attribute that has some > > > other value" template</xsl:comment> > > > </xsl:template> > > > > > > </xsl:stylesheet> > > > > > > How can I select only the nodes with "Apply=1", drop everything else > > > like, apply=0 or any value and even if apply attribute is not there at > > > all. I need to still maintain the hierarchy. eg. Parent, sub1 etc did > > > not have apply attribute at all. But that has to be preserved, because > > > thats the hierarchy. > > > > > > Thanks > > > Senthil > > > > > > -- > > Regards, > > Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] copy nodes based on the c, Mukul Gandhi | Thread | Re: [xsl] copy nodes based on the c, Mukul Gandhi |
Re: [xsl] copy nodes based on the c, Mukul Gandhi | Date | [xsl] stylesheet expansion, Geert Bormans |
Month |
Keywords