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

Re: Enabling extension to counting of instances

Subject: Re: Enabling extension to counting of instances
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 8 Jan 2010 09:40:04 -0800
Re:  Enabling extension to counting of instances
Here is the filter() function of FXSL (written around 2003/2004):

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f xs"
>

  <xsl:import href="func-apply.xsl"/>

  <xsl:function name="f:filter" as="item()*">
    <xsl:param name="pList"  as="item()*"/>
    <xsl:param name="pController" as="element()"/>

    <xsl:sequence select="$pList[f:apply($pController, .)]"/>
  </xsl:function>
</xsl:stylesheet>

the $pController is a "template reference". When it is applied to an
item of the sequense $pList, it returns true() or false(), using
whatever logic is needed for that and we (f:filter() ) don't care and
don't know / cannot anticipate that.


Here is a simple example (testFunc-filter.xsl in the distribution of
FXSL 2.x) using f:filter():

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:f="http://fxsl.sf.net/"
exclude-result-prefixes="f"
>

  <xsl:import href="../f/func-filter.xsl"/>
  <xsl:import href="../f/func-Operators.xsl"/>
  <xsl:import href="../f/func-standardXpathFunctions.xsl"/>
  <xsl:import href="../f/func-flip.xsl"/>
  <xsl:import href="../f/func-compose.xsl"/>

  <!--

       Expected result:
               Filtering by IsEven:
	       2 4 6 8 10

-->

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

  <xsl:template match="/">
    Filtering by IsEven:


    <xsl:sequence select="f:filter(1 to 10, f:compose(f:not(),
f:flip(f:mod(),2)))"/>
  </xsl:template>
</xsl:stylesheet>


When the above transformation is applied (on any source xml -- not
used) the expected result is produced:

"
    Filtering by IsEven:


    2 4 6 8 10
"

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Fri, Jan 8, 2010 at 9:27 AM, Eliot Kimber <ekimber@xxxxxxxxxxxx> wrote:
> On 1/8/10 11:25 AM, "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> wrote:
>
>> I personally would use a function (predicate that decides if something
>> is a "chapter") passed as a parameter (function-item in 2.1 speak).
>
> Can you provide an example of how that would work?
>
> Thanks,
>
> E.
>
>
> --
> Eliot Kimber
> Senior Solutions Architect
> "Bringing Strategy, Content, and Technology Together"
> Main: 610.631.6770
> www.reallysi.com
> www.rsuitecms.com

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.