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

RE: RE: Filtering using list of params (Subtree creati

Subject: RE: RE: Filtering using list of params (Subtree creation?)
From: cknell@xxxxxxxxxx
Date: Wed, 19 Nov 2003 13:19:48 -0500
xlst sum
The easiest way to solve this is to restructure the XML, if possible. Then your input could look like this:

<root>
  <europe>
    <store location="london">
      <staff>100</staff>
    </store>
    <store location="paris">
      <staff>50</staff>
    </store>
    <store location="madrid">
      <staff>25</staff>
    </store>
  </europe>
  <north-america>
    <store location="new york">
      <staff>200</staff>
    </store>
  </north-america>
  <asia>
    <store location="tokyo">
      <staff>125</staff>
    </store>
  </asia>
</root>

And summing any particular group is easy the the XLST sum() function:

  <xsl:template match="/root">
    <xsl:variable name ="staffing" select="sum(europe/store/staff)" />
    <xsl:value-of select="$staffing" />
  </xsl:template>

If you can't get the producer of the XML to group the data like this, we'll have to try another approach.
-- 
Charles Knell
cknell@xxxxxxxxxx - email



-----Original Message-----
From:     Chris Ward <cward@xxxxxxxxxxxxxxxxxxx>
Sent:     Wed, 19 Nov 2003 16:30:25 -0000
To:       <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  RE:  Filtering using list of params (Subtree creation?)


Thanks Charles.  However, if fear that the <xsl:choose> solution (below)
would move the problem I'm having into the other named templates.
Specifically the "euro" template which should do a SUM() on a selection
-
but not all - stores.

I'll try to better summarse my problem...

Given...



How can I do something along the lines of 

	SUM( staff for london, madrid, paris )


where the list of locations is dynamic (possibly in a separate XML
document).


I don't know if this makes it any clearer.  

Regards,
Chris



> >
> > I want to know if there is a preferred method of filtering out 
> > multiple parts of a large XML using some form of parameter 
> > list/document.
> 
> I suggest two possible approaches, neither of which is what 
> you describe:
> 
> 1) Create a stylesheet for each view and select the 
> appropriate one based on values from the query string of the 
> submitting page.
> 
> 2) Create a "view" parameter in single stylesheet with a 
> large <xsl:choose> section. Then create individual named 
> templates to be called based on the value of the view 
> parameter as determined in the <xsl:choose>. Like this:
> 
>   <xsl:param name="view" />
>   
>   <xsl:template match="/">
>     <xsl:choose>
>       <xsl:when test="$view = 'global'>
>         <xsl:call-template name="global" />
>       </xsl:when>
>       <xsl:when test="$view = 'euro'>
>         <xsl:call-template name="euro" />
>       </xsl:when>
>       <xsl:when test="$view = 'london'>
>         <xsl:call-template name="london" />
>       </xsl:when>
>       <xsl:when test="$view = 'new york'>
>         <xsl:call-template name="new-york" />
>       </xsl:when>
>       <xsl:when test="$view = 'paris'>
>         <xsl:call-template name="paris" />
>       </xsl:when>
>       <xsl:when test="$view = 'madrid'>
>         <xsl:call-template name="madrid" />
>       </xsl:when>
>       <xsl:when test="$view = 'tokyo'>
>         <xsl:call-template name="tokyo" />
>       </xsl:when>
>       <xsl:otherwise>
>         <xsl:call-template name="not-authorized" />
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
> -- 
> Charles Knell
> cknell@xxxxxxxxxx - email
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

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




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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.