Re: [xsl] $5 PAYPAL for correct answer still not claimed! Searching for an attribute across different elements with ancestoral elements returned

Subject: Re: [xsl] $5 PAYPAL for correct answer still not claimed! Searching for an attribute across different elements with ancestoral elements returned
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Fri, 20 Jul 2001 03:37:40 -0700
Please disregard prior... premature send.

At 03:05 20-07-2001, David Glover wrote:
I wish to return all brands/lines/items that have this @OFFER attribute.

This is the confusing part. What do you mean by "return"?


An XPath expression matches nodes. You could have an expression that matches the brands, or, lines, or items, or all of them, but it's not clear what the value of matching all of them would be.

Now, if by "return" you mean "copy into the result tree", i.e. copy the source tree but prune any branches that don't have offers, then what you probably want to do is have a template that matches any BRAND with an offer on any descendant, and then only process the ITEMs with any offers, etc.

<!-- by default, don't copy anything -->
<xsl:template match="BRAND | LINE | ITEM" priority="1"/>

<!-- if there are children with offers, copy this element and then look
     at its children one by one -->
<xsl:template match="BRAND[LINE/@OFFER or LINE/ITEM/@OFFER] |
                     LINE[ITEM/@OFFER]" priority="2">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<!-- if this one has the offer, copy it and all its descendants -->
<xsl:template match="BRAND[@OFFER] | LINE[@OFFER] |
                     ITEM[@OFFER]" priority="3">
  <xsl:copy-of select="."/>
</xsl:template>

Based on your example, this should do what you want.

HTH,
Chris
--
Christopher R. Maden, XML Consultant
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread