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

RE: Can grouping here the solution ?

Subject: RE: Can grouping here the solution ?
From: Robby Pelssers <Robby.Pelssers@xxxxxxx>
Date: Mon, 21 Nov 2011 19:07:18 +0100
RE:  Can grouping here the solution ?
I still don't see the problem.  The grouping example I gave is done based on
the sample data from your mail.

Nothing is preventing you to check each group for some condition before
applying templates.

<xsl:for-each group select="display-articles/section/entry"
group-by="concat(substring(datum/text(), 1,7), '/', page/text())">
<!-- this way you group on unique combinations of e.g. strings like
'2005-02/1' -->
  <xsl:if test="current-grouping-key() eq '2005-02/1'">
     <xsl:apply-templates select="current-group()"/>
  </xsl:if>
</xsl:for-each>

But to me it seems like you don't even need grouping.

Assuming you inject any parameters from the url by setting the predefined
'monthOfYear' and 'page' parameters

<xsl:param name="monthOfYear" as="xs:string"/> <!-- assuming you inject a
string of format '2005-02' -->
<xsl:param name="page" as="xs:integer"/>

<!-- we only need to handle entries which satisfy both $monthOfYear and $page
<xsl:apply-templates
select="display-articles/section/entry[substring(datum/text(), 1,7) eq
$monthOfYear and page/text() eq $page]"/>

Robby

-----Original Message-----
From: Roelof Wobben [mailto:rwobben@xxxxxxxxxxx]
Sent: Monday, November 21, 2011 6:53 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Can grouping here the solution ?


Thanks but the problem is that the 2005-02 is on the url but the pagenumber is
a xslt variable which is not on the url.



Roelof



----------------------------------------
> From: Robby.Pelssers@xxxxxxx
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Date: Mon, 21 Nov 2011 18:41:58 +0100
> Subject: RE:  Can grouping here the solution ?
>
> You can do something like
>
> <xsl:for-each group select="display-articles/section/entry"
group-by="concat(substring(datum/text(), 1,7), '/', page/text())">
> <!-- this way you group on unique combinations of e.g. strings like
'2005-02/1' -->
> </xsl:for-each>
>
> Robby
>
> -----Original Message-----
> From: Roelof Wobben [mailto:rwobben@xxxxxxxxxxx]
> Sent: Monday, November 21, 2011 6:33 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  Can grouping here the solution ?
>
>
> what I try to achieve is this.
>
>
>
> As you can see I have some articles for testing purposes.
>
> I like to display them per month and per page where I can decide how many
articles are displayed.
>
> This depends on the month and the page the user is on my website.
>
>
>
> I hope it's clear what I want.
>
>
>
> Roelof
>
>
>
> ----------------------------------------
> > Date: Mon, 21 Nov 2011 11:45:42 -0500
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > From: gkholman@xxxxxxxxxxxxxxxxxxxx
> > Subject: RE:  Can grouping here the solution ?
> >
> > At 2011-11-21 16:29 +0000, Roelof Wobben wrote:
> > >Can I select the group on multiple things
> >
> > Yes, by grouping the groups as I showed you.
> >
> > >This script does what i need but I don't see how I can take care
> > >that ony 1 month and 1 page are displayed.
> >
> > I do not understand your concern. Can you please post what you want
> > to display for the XML content you showed us?
> >
> > Perhaps the problem is in your choice of the word "grouping". If you
> > want to only show from your content all of the titles for a given
> > month and page, then you do not need grouping, you only need filtering.
> >
> > I hope the filtering example below helps. It does not rely on grouping.
> >
> > . . . . . . . . . . Ken
> >
> > t:\ftemp>type roelof.xml
> > <?xml version="1.0" encoding="UTF-8"?>
> > <display-articles>
> > <section id="1" handle="blog">Blog</section>
> > <entry id="1">
> > <titel handle="zwanger">Zwanger ??</titel>
> > <datum time="23:00" weekday="5">2005-02-04</datum>
> > <page>1</page>
> > <tekst mode="formatted"><p>Hoera, het is zover, eindelijk (...)</p>
> > </tekst>
> > </entry>
> > <entry id="2">
> > <titel handle="7-weken-echo">7 weken echo</titel>
> > <datum time="22:00" weekday="1">2005-02-21</datum>
> > <page>1</page>
> > <tekst mode="formatted"><p>Ik stond al onder behandeling (...)</p>
> > </tekst>
> > </entry>
> > <entry id="3">
> > <titel handle="appelgebak">Appelgebak</titel>
> > <datum time="23:00" weekday="6">2005-02-26</datum>
> > <page>2</page>
> > <tekst mode="formatted"><p>Met appelgebak zijn we naar jouw (...)</p>
> > </tekst>
> > </entry>
> > </display-articles>
> >
> > t:\ftemp>xslt2 roelof.xml roelof2.xsl roelof.out "month=02" "page=2"
> >
> > t:\ftemp>type roelof.out
> > For month "02" and page "2":
> > Appelgebak
> >
> > t:\ftemp>xslt2 roelof.xml roelof2.xsl roelof.out "month=02" "page=1"
> >
> > t:\ftemp>type roelof.out
> > For month "02" and page "1":
> > Zwanger ??
> > 7 weken echo
> >
> > t:\ftemp>type roelof2.xsl
> > <?xml version="1.0" encoding="UTF-8"?>
> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > version="2.0">
> > <xsl:output method="text"/>
> >
> > <xsl:param name="month" required="yes"/>
> > <xsl:param name="page" required="yes"/>
> >
> > <xsl:template match="display-articles">
> > <xsl:text>For month "</xsl:text>
> > <xsl:value-of select="$month"/>
> > <xsl:text>" and page "</xsl:text>
> > <xsl:value-of select="$page"/>
> > <xsl:text>":
> > </xsl:text>
> > <xsl:for-each select="entry[substring(datum,6,2)=$month and page=$page]">
> > <xsl:value-of select="titel"/>
> > <xsl:text>
> > </xsl:text>
> > </xsl:for-each>
> > </xsl:template>
> >
> > </xsl:stylesheet>
> > t:\ftemp>
> >
> >
> > --
> > Contact us for world-wide XML consulting and instructor-led training
> > Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/t37DVX
> > Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
> > G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> > Google+ profile: https://plus.google.com/116832879756988317389/about
> > Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.