Re: [xsl] Remove node after testing for equality using value from external xml document

Subject: Re: [xsl] 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
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 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:

your main file:

You'll want (in XSLT 2.0)

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

Jon Gorman

Current Thread