xsl-list
[Top] [All Lists]

Re: Tricky inclusion match

2005-03-29 09:35:35
Thanks for the 2.0 spec.
I'm probably going down that route, with some more questions on data
aggregation... I need to summarize data based on the result of an
apply-templates.  Man, this is getting ugly... but I am faithful there
is a very realistic 1.0 solution!

So, let me ask the following question:
Use a variable to store the results of an apply-templates rule.  The
result is a new element which might look something like this:
<data>
  <value>1</value>
  <value>1</value>
</data>

How can I aggregate (sum) the above data element which is stored in a variable?

Karl


On Tue, 29 Mar 2005 08:26:15 -0800 (PST), Mukul Gandhi
<mukul_gandhi(_at_)yahoo(_dot_)com> wrote:
Following is a XSLT 2.0 solution..

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

<xsl:output method="text" />

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

 <xsl:for-each select="pictures/picture">
   <xsl:variable name="temp2"
select="distinct-values(color)" />
   <xsl:if
test="count(distinct-values($temp1[.=$temp2])) >
1">
     picture sample #<xsl:value-of select="@sample"
/><xsl:text>
</xsl:text>
   </xsl:if>
 </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

The expression distinct-values($temp1[.=$temp2]) finds
the intersection of sequences $temp1 and $temp2.

XSLT processor used: Saxon 8.3 ..

Regards,
Mukul

--- Karl Stubsjoen <kstubs(_at_)gmail(_dot_)com> wrote:
Okay,
Lets say you have a set of colors and you have a
whole bunch of
pictures and you want to match on all pictures who
have one or more of
the given colors but you have to at least match on 2
of them (unique,
so not red and red - so a picture could list red
twice but that would
not be a match).  I'm trying to use keys and
grouping to solve this
but thinking that I might be making this more
difficult.  At any rate,
I'm stuck and would appreciate some help : )

Sample Data (expected results below):

<data>
    <colors>
      <color>red</color>
      <color>blue</color>
      <color>fucia</color>
      <color>violet</color>
    </colors>
    <pictures>
      <picture sample="1">
              <color>black</color>
              <color>grey</color>
              <color>white</color>
        </picture>
      <picture sample="2">
              <color>red</color>
              <color>green</color>
              <color>brown</color>
              <color>blue</color>
        </picture>
      <picture sample="3">
              <color>purple</color>
              <color>orange</color>
        </picture>
      <picture sample="4">
              <color>blue</color>
              <color>green</color>
              <color>red</color>
        </picture>
      <picture sample="5">
              <color>fucia</color>
              <color>green</color>
              <color>violet</color>
        </picture>
      <picture sample="6">
              <color>red</color>
              <color>brown</color>
              <color>red</color>
        </picture>
    </pictures>
</data>

Expected Results (picture matches based on 2 or more
colors used and
listed in colors above)

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


--~------------------------------------------------------------------
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>