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

Re: Remove node after testing for equality using value

Subject: Re: Remove node after testing for equality using value from external xml document
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Thu, 9 Feb 2006 09:14:35 -0600
xsl remove nodes
Well, like I mentioned before this would be a good time to use keys.
It varies a bit by whether you want the 1.0 solution or the 2.0
solution I believe.

See http://www.dpawson.co.uk/xsl/sect2/N4852.html#d5694e1248 for more
info on how to do it in either case.

Since I've had one or two people comment that just pointing to the faq
isn't always helpful I'll give a very, very quick and dirty (and quite
possible error-ridden example) on the below.


> I should have stated that I am trying to remove nodes that have a
> HARDWARE_PART_NO = to the corresponding HARDWARE_PART_NO in an external
> XML document.
...
> What I think the test should look like is something along the lines of:
>
> >             <xsl:when test="self::Row[HARDWARE_PART_NO != 'Param or
> Variable']">
> >                 <xsl:comment>Structural Part No Removed</xsl:comment>
>

So....I'm just going to take a wild stab and assume you meant that you
want to display only those nodes that have a part number in the
different file, since again you're contradicting yourself.  (Do you
want the nodes to be excluded when they are in the lookup file or when
they are not in the lookup file?)  I'm also not sure why you are just
commenting out the part number.  It would seem more useful just to
retrieve the parent node where the part number is found in the lookup
(and maybe comment out the info inside).


So lets say you have:

lookup file:
<partnos>
<partno>12</partno>
<partno>3</partno>
</partnos>

your main file:
<inventory>
<hardware>
   <partno>12</partno>
   <foo>bar</foo>
</hardware>
<hardware>
   <partno>3</partno>
   <foo>bar</foo>
</hardware>
</inventory>

You'll want (in XSLT 2.0)

<xsl:template match="partno">
  <xsl:choose>
<xls:when "key('k', @code,document('lookup.xml')) != ''">
    <!-- stick the identity transform here, ie copy the node and
apply-templates to children -->
</xsl:when>
<!-- no value in the key (hash) so not in the lookup file, comment out -->
<xsl:otherwise>
<xsl:comment>Part number Removed</xsl:comment>
</xsl:otherwise>
</xsl:template>


Jon Gorman

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-2011 All Rights Reserved.