[Home] [By Thread] [By Date] [Recent Entries]
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>
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
|

Cart



