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

Re: Tricky inclusion match

Subject: Re: Tricky inclusion match
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 29 Mar 2005 18:26:06 -0500
color match

It turned out that keys weren't actually necessary: as posed (as I understand it) the colors problem could be solved with a simple (if not obvious) test. But using a key does make it slightly more efficient:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:key name="pictures-by-color" match="picture" use="color"/>

<xsl:variable name="colors" select="/data/colors/color"/>

  <xsl:template match="data">
    <xsl:apply-templates select="colors"/>
    <!-- if we weren't going to select using the key, we could go straight to
         the pictures; but then we'd be testing each one -->

  <xsl:template match="colors">
    <xsl:apply-templates select="key('pictures-by-color',color)"/>
    <!-- by using the key we select just the pictures that have at least
         one color matching a color in your set -->

<xsl:template match="picture">
<xsl:if test="count(color[not(.=preceding-sibling::color)][.=$colors]) &gt;= 2">
<xsl:text>&#xA;picture sample #</xsl:text>
<xsl:value-of select="@sample"/>


results (over your original data):

picture sample #2
picture sample #4
picture sample #5

-- which I think you said is what you want.

The action is in that count of the colors inside each picture:


The first predicate deduplicates each color against its siblings; the second sees whether it's listed among the colors you want. This yields the set of unique colors (within each parent) listed among the colors of interest, which you can count.

Note that it's a brute-force deduplication; if you have lots and lots of siblings you could optimize that first predicate (using another key).

I hope that's what you were after --


At 06:12 PM 3/29/2005, you wrote:
I am much insterested in your XSLT 1.0 solution to the original colors
problem.  Indeed, it is the "simple" version of the problem which I am
Thanks.  Karl

====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread


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.
First Name
Last Name
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-2013 All Rights Reserved.