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

Re: xpath - how to return all nodes but the node match

Subject: Re: xpath - how to return all nodes but the node matching a value in an arbitrary tree?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 04 May 2002 22:54:21 -0400
xslt match all nodes
At 2002-05-04 10:27 -0700, Scott Zagar wrote:
In order to "delete" a node, I'm trying to write an xpath that, when given
an id, will return the entire tree with the exception of the matching node
for the id.

This must be done using the processing model of XSLT and cannot be done with a single XPath expression.


I hope the solution below helps. I left every other parameter you used untouched.

............. Ken

t:\ftemp>type scott.xml
<category id="5">music
 <category id="6">blues
  <artist id="7">bb king</artist>
  <artist id="8">lightnin hopkins</artist>
 </category>
 <category id="6">jazz
  <category id="11">bebop
   <artist id="12">charlie parker</artist>
  </category>
  <artist id="9">miles davis</artist>
  <artist id="10">john coltrane</artist>
 </category>
</category>

t:\ftemp>type scott.xsl
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
 <xsl:output
  method="xml"
  indent="yes"
  omit-xml-declaration="yes"
  cdata-section-elements="category artist" />
 <xsl:param name="delete_id"/>
 <xsl:template match="/|*|text()|processing-instruction()|comment()"
               name="copy-me">
  <xsl:copy><!--copy all elements if this were the only rule-->
   <xsl:copy-of select="@*"/>
   <xsl:apply-templates select="node()"/>
  </xsl:copy>
 </xsl:template>
 <xsl:template match="artist">
   <xsl:if test="@id != $delete_id">
     <xsl:call-template name="copy-me"/>
   </xsl:if>
 </xsl:template>
</xsl:stylesheet>

t:\ftemp>saxon scott.xml scott.xsl delete_id="7"
<category id="5"><![CDATA[music
 ]]><category id="6"><![CDATA[blues

  ]]><artist id="8"><![CDATA[lightnin hopkins]]></artist><![CDATA[
 ]]></category><![CDATA[
 ]]><category id="6"><![CDATA[jazz
  ]]><category id="11"><![CDATA[bebop
   ]]><artist id="12"><![CDATA[charlie parker]]></artist><![CDATA[
  ]]></category><![CDATA[
  ]]><artist id="9"><![CDATA[miles davis]]></artist><![CDATA[
  ]]><artist id="10"><![CDATA[john coltrane]]></artist><![CDATA[
 ]]></category><![CDATA[
]]></category>
t:\ftemp>


-- Upcoming: 3-days XSLT/XPath and/or 2-days XSLFO: June 17-21, 2002 - : 3-days XML Information Modeling: July 31-August 2, 2002

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6                      Definitive XSLT and XPath
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1               Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training:               2002-05-06,07,09,10,13,15,20,
-                    06-04,07,10,11,13,14,17,20,07-31,08-05,27,30


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.