Subject: Re: [xsl] Enabling extension to counting of instances From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Fri, 8 Jan 2010 09:40:04 -0800 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Enabling extension to cou, Eliot Kimber | Thread | Re: [xsl] Enabling extension to cou, Eliot Kimber |
Re: [xsl] Enabling extension to cou, Eliot Kimber | Date | Re: [xsl] Enabling extension to cou, Eliot Kimber |
Month |