Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] xpath - how to return all nodes but the node matching a value in an arbitrary tree?

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 5/4/2002 6:50:00 PM
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


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent