|
[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 avalue in an arbitrary tree?
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Sat, 04 May 2002 10:40:00 -0700
|
Hi,
Here you go:
<xsl:template match="node()|@*">
<xsl:if test="not(@id=$id)">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:if>
</xsl:template>
best,
-Rob
Scott Zagar wrote:
Hello,
I have a heirarchical categorization which I'm trying to manipulate via XSL
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. I've tried many possibilities but can't seem to get the thing to
work -- many times it just skips the match all together and returns the
whole tree. Since the heirarchical structure is arbitrary, I cannot just
pinpoint the exact location of the node to be removed -- I suppose I could
with two stylesheets, but I have a feeling there is a more elegant solution
with a single xpath.
Can someone please help me with the xpath that would return the whole tree,
minus the node?
Thanks,
Scott Zagar
Here's a mockup of the XML ... the structure is arbitrary:
<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>
Here's the XSL, in this example I'm trying to return everything but the
artist node matching the delete_id parameter :
<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="/">
<xsl:copy-of select="//category//artist[@id!=$delete_id]"/> <---------
this is it
</xsl:template>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
| RSS 2.0 |
|
| Atom 0.3 |
|
|