|
Subject: Re: [xsl] Filtering out nodes between bookmarks From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 26 Feb 2008 14:03:19 -0500 |
What is the best approach to remove any nodes between 2 marker elements matching by their id attributes? ... Sorry for the incomplete xml fragment, but those bookmarks could be pretty much anywhere in hierarchy.
t:\ftemp>type daniloff.xml <root> <body> <para> .... </para>
<para>
<a/>
<bookmarkStart id="1"/>
<b/>
....
</para><para> .... </para>
<table> ... </table>
<c/> <bookmarkEnd id="1"/> <d/>
<para> .... </para>
</body> </root>
t:\ftemp>type daniloff.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:variable name="bookmarkIDs" select="//bookmarkStart/@id"/> <xsl:key name="bookmarkStarts" match="bookmarkStart" use="@id"/> <xsl:key name="bookmarkEnds" match="bookmarkEnd" use="@id"/>
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="some $b in $bookmarkIDs satisfies
( . >> key('bookmarkStarts',$b) and
key('bookmarkEnds',$b) >> . )">
<!--remove the node-->
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template></xsl:stylesheet> t:\ftemp>xslt2 daniloff.xml daniloff.xsl con <?xml version="1.0" encoding="UTF-8"?><root> <body> <para> .... </para>
<para>
<a/>
<bookmarkStart id="1"/></para><bookmarkEnd id="1"/>
<d/><para> .... </para>
</body> </root> t:\ftemp>
-- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training 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 (F:-0995) Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Filtering out nodes between b, Michael Daniloff | Thread | Re: [xsl] Filtering out nodes betwe, David Carlisle |
| Re: [xsl] XSLT 2.0 XML Schema defin, Johannes Neubauer | Date | Re: [xsl] Filtering out nodes betwe, David Carlisle |
| Month |