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

copy nodes based on the criteria

Subject: copy nodes based on the criteria
From: "Senthil Nathan" <rsennat@xxxxxxxxx>
Date: Fri, 7 Dec 2007 21:59:54 +0530
 copy nodes based on the criteria
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

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.