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

RE: AW: tricky problem filtering input and counting o

Subject: RE: AW: tricky problem filtering input and counting output
From: "Trevor Nicholls" <trevor@xxxxxxxxxxxxxxxxxx>
Date: Wed, 23 Feb 2011 07:32:09 +1300
RE: AW:  tricky problem filtering input and counting  o
Hi Wendell, (& thanks Patrick)

I think running a separate pass to filter the input XML file is the simplest
solution and I will try that straight away. I don't know why it didn't occur
to me already. Strangely (it seems to me) I typed up the whole post and before
wondering what to put in the subject. Now that I look at the subject, I see
that I practically described a two-step solution in half a sentence :-(

But seeing as you asked, here is what is going on with the filtering.

 <xsl:param name="filterversions" />
 <xsl:param name="filterplatforms" />

 <xsl:template name="filter-output">
  <xsl:param name="version" />
  <xsl:param name="platform" />
 <!-- version -->
  <xsl:variable name="versionchk">
    <xsl:when test="$version != ''">
     <xsl:if test="contains($filterversions,$version)">
 <!-- platform -->
  <xsl:variable name="platformchk">
    <xsl:when test="$platform != ''">
     <xsl:if test="contains($filterplatforms,$platform)">
 <!-- all together now -->
  <xsl:if test="concat($versionchk,$platformchk) = 'YY'">

My original sample had
 <xsl:call-template name="filter-output" />

but this template has some parameters of course, which are obtained either
from version/platform attributes on the context element (document or section)
or from higher up the node tree, or from an external document.

  <xsl:variable name="select">
   <xsl:call-template name="filter-output">
    <xsl:with-param name="version">
     <xsl:call-template name="get-version" />
    <xsl:with-param name="platform" select="@platform" />

where get-version is something like this:

 <xsl:template name="get-version">
  <xsl:variable name="localv">
   <xsl:value-of select="(ancestor-or-self::*/@version[. != ''])[last()]" />
  <xsl:variable name="external">
   <xsl:value-of select="document('catalog.xml',/)/files/file[. =
$me]/@version" />
   <xsl:when test="$localv != ''">
    <xsl:value-of select="$localv" />
    <xsl:value-of select="$externalv" />

$me is another global parameter identifying the XML file.

The expression for $localv is the way it is because I may need to use min() or
max() instead of last().

And now I expect you to glance at that and say, "yes, pipelining" without a
moment's thought :-)


-----Original Message-----
From: Wendell Piez [mailto:wapiez@xxxxxxxxxxxxxxxx]
Sent: Wednesday, 23 February 2011 6:25 a.m.
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: AW:  tricky problem filtering input and counting output


On 2/22/2011 9:44 AM, Szabo, Patrick (LNG-VIE) wrote:
> I hope I'm imagining this correctly. Couldn't you filter the input
> before you do the counting ?!
> You could dump the document and sections elements you don't need and
> count afterwards.

Yes: Trevor's Gordian knot can be cut by pipelining. Filter the document
first, then run the transformation to generate the output.

A solution in one pass is also possible -- and might even be fairly
clean -- but how it would work best might depend on details of the
filtering requirement. Trevor, you haven't shown us the "filter-output"
template so we don't know what it does and whether it can be refactored
and simplified.

Also, much is possible in XSLT 2.0. For example, if that logic were in a
function instead of a template....


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.