Subject: Re: [xsl] Enabling extension to counting of instances From: Eliot Kimber <ekimber@xxxxxxxxxxxx> Date: Fri, 08 Jan 2010 12:00:27 -0600 |
I'm not sure how this satisfies my requirement for abitrary included XSLT modules to contribute to the filter function, but it's possible I'm not fully understanding the processing implications here since there's a bit of indirection. Cheers, E. On 1/8/10 11:40 AM, "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> wrote: > 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 > " -- Eliot Kimber Senior Solutions Architect "Bringing Strategy, Content, and Technology Together" Main: 610.631.6770 www.reallysi.com www.rsuitecms.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Enabling extension to cou, Dimitre Novatchev | Thread | Re: [xsl] Enabling extension to cou, Dimitre Novatchev |
Re: [xsl] Enabling extension to cou, Dimitre Novatchev | Date | Re: [xsl] Enabling extension to cou, Dimitre Novatchev |
Month |