Re: [xsl] Tricky inclusion match

Subject: Re: [xsl] Tricky inclusion match
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 31 Mar 2005 11:58:11 -0500
At 12:49 AM 3/31/2005, Dimitre wrote:
Seems a little bit too long.

This transformation:

<xsl:stylesheet version="1.0"

<xsl:output omit-xml-declaration="yes"/>

<xsl:variable name="vColors" select="/*/colors"/>

  <xsl:template match="/">
    <xsl:for-each select="/*/*/picture">
      <xsl:if test="count($vColors/*[. = current()/color]) >= 2">
        <xsl:value-of select="concat('Picture Id=', @sample, '&#xA;')"/>

when performed against the originally posted source xml document,
produces the wanted result:

Picture Id=2
Picture Id=4
Picture Id=5


It doesn't have to de-duplicate because it is able to assume there are no duplicates among the colors listed in $vColors.

This could be further compressed, too:

  select="/*/*/picture[count($vColors/*[. = current()/color]) >= 2]" />

(with a template matching the picture)

Always more to learn....

Thanks, Dimitre!


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 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