Re: Tricky inclusion 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>
<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>
<xsl:if test="count(color[not(.=preceding-sibling::color)][.=$colors]) >= 2">
picture sample #</xsl:text>
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:
Wendell: 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 facing. Thanks. Karl
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format