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 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