RE: [xsl] Can grouping here the solution ?
2011-11-22 03:18:05
Ok.. don't know where I got that display articles from ... probably from prior
sample data you showed me.
But in fact this one was easy to figure out yourself. Just check the data
structure and see if you match on meaningful tags.
In this case it had to be
<xsl:template match="/">
<xsl:apply-templates select="artikel-details"/>
</xsl:template>
Robby
-----Original Message-----
From: Roelof Wobben [mailto:rwobben(_at_)hotmail(_dot_)com]
Sent: Tuesday, November 22, 2011 10:09 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Can grouping here the solution ?
I change it as you said.
So it looks now like this :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:param name="pageNumber"/>
<xsl:template match="/">
<xsl:apply-templates select="display-articles"/>
</xsl:template>
<xsl:template match="display-articles">
<xsl:for-each-group select="entry" group-by="page">
<xsl:if test="current-grouping-key() eq $pageNumber">
<xsl:apply-templates select="current-group()"/>
</xsl:if>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="entry">
<h1><xsl:value-of select="titel"/></h1><br />
<xsl:value-of select="datum" /><br />
<xsl:value-of select="tekst" />
</xsl:template>
</xsl:stylesheet>
But no I get this as output :
The XSL transformation did not create any output.
Roelof
----------------------------------------
From: Robby(_dot_)Pelssers(_at_)nxp(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: Tue, 22 Nov 2011 10:03:37 +0100
Subject: RE: [xsl] Can grouping here the solution ?
You actually did not misunderstood anything..
The only thing you need to add is a root matcher and from there you start the
flow as you want it. The reason why you get the text output is because since
you left out a / matching template, all text nodes are copied in to the
result as well.
Add the template below and you should get what you want.
<xsl:template match="/">
<xsl:apply-templates select="display-articles"/>
</xsl:template>
Robby
-----Original Message-----
From: Roelof Wobben [mailto:rwobben(_at_)hotmail(_dot_)com]
Sent: Tuesday, November 22, 2011 9:59 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Can grouping here the solution ?
One problem.
I did make this xslt to test your code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:param name="pageNumber"/>
<xsl:template match="display-articles">
<xsl:for-each-group select="entry" group-by="page">
<xsl:if test="current-grouping-key() eq $pageNumber">
<xsl:apply-templates select="current-group()"/>
</xsl:if>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="entry">
<h1><xsl:value-of select="titel"/></h1><br />
<xsl:value-of select="datum" /><br />
<xsl:value-of select="tekst" />
</xsl:template>
</xsl:stylesheet>
And I used this xml file :
?xml version="1.0" encoding="utf-8" ?>
<artikel-details>
<section id="1" handle="blog">Blog</section>
<entry id="1"> 30 <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 zwanger. De test
laat niets te twijfelen over. Ik ben net een stuiterbal, blij en energie voor
tien. Ondanks het prille begin, heb ik een goed gevoel over deze
zwangerschap. Waarom? geen idee. Het voelt gewoon goed. Het is moeilijk om 's
middags mijn mond dicht te houden als ik met mijn zus in de stad ben. Het is
maar goed dat er een carnavalsoptocht is, het geeft een beetje afleiding.</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 van een gynaecoloog
en heb een echo gehad om te kijken of alles goed met je is. Ons kleintje (zo
noem ik je) je bent 7 weken en 6,5 millimeter, onvoorstelbaar dat je nu al
jouw hartje kunt zien kloppen. De vermoedelijke bevallingsdatum wordt op 9
oktober 2005 vastgesteld, Tjonge wat klinkt dat nog ver weg. De energie voor
10 was van korte duur, veel slaap is ervoor in de plaats gekomen, 's avonds
om acht uur rol ik om van de slaap. Gekke gewoonte: waterijs, ik kan er niet
vanaf blijven, spekjes en zuurtjes. Waar ik een hekel aan heb gekregen, kip
snijden en bakken en de geur van wokolie. Bah, wat smerig.</p>
</tekst>
</entry>
<entry id="3">
<titel handle="appelgebak">Appelgebak</titel>
<datum time="23:00" weekday="6">2005-02-26</datum>
<page>1</page>
<tekst mode="formatted"><p>Met appelgebak zijn we naar jouw opa Mans en oma
Marie gegaan. Ze zijn blij voor ons en ik hoop dat je veel plezier zult
hebben met je opa Mans en oma Marie zodra je bent geboren. Nu nog opa Jan en
Dagmar vertellen dat je op komst bent</p>
</tekst>
</entry>
</artikel-details>
But I see as output this :
<!DOCTYPE h1 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">Blog<h1>Zwanger
??</h1><br/>2005-02-04<br/>Hoera, het is zover, eindelijk zwanger. De test
laat niets te twijfelen over. Ik ben net een stuiterbal, blij en energie voor
tien. Ondanks het prille begin, heb ik een goed gevoel over deze
zwangerschap. Waarom? geen idee. Het voelt gewoon goed. Het is moeilijk om 's
middags mijn mond dicht te houden als ik met mijn zus in de stad ben. Het is
maar goed dat er een carnavalsoptocht is, het geeft een beetje
afleiding.<h1>7 weken echo</h1><br/>2005-02-21<br/>Ik stond al onder
behandeling van een gynaecoloog en heb een echo gehad om te kijken of alles
goed met je is. Ons kleintje (zo noem ik je) je bent 7 weken en 6,5
millimeter, onvoorstelbaar dat je nu al jouw hartje kunt zien kloppen. De
vermoedelijke bevallingsdatum wordt op 9 oktober 2005 vastgesteld, Tjonge wat
klinkt dat nog ver weg. De energie voor 10 was van korte duur, veel slaap is
ervoor in de plaats gekomen, 's avonds om acht uur rol ik om van de slaap.
Gekke gewoonte: waterijs, ik kan er niet vanaf blijven, spekjes en zuurtjes.
Waar ik een hekel aan heb gekregen, kip snijden en bakken en de geur van
wokolie. Bah, wat smerig.<h1>Appelgebak</h1><br/>2005-02-26<br/>Met
appelgebak zijn we naar jouw opa Mans en oma Marie gegaan. Ze zijn blij voor
ons en ik hoop dat je veel plezier zult hebben met je opa Mans en oma Marie
zodra je bent geboren. Nu nog opa Jan en Dagmar vertellen dat je op komst bent
Instead of
Zwanger ??
Hoera, het is zover, eindelijk zwanger. De test laat niets te twijfelen over.
Ik ben net een stuiterbal, blij en energie voor tien. Ondanks het prille
begin, heb ik een goed gevoel over deze zwangerschap. Waarom? geen idee. Het
voelt gewoon goed. Het is moeilijk om 's middags mijn mond dicht te houden
als ik met mijn zus in de stad ben. Het is maar goed dat er een
carnavalsoptocht is, het geeft een beetje afleiding
7 weken echo
Ik stond al onder behandeling van een gynaecoloog en heb een echo gehad om te
kijken of alles goed met je is. Ons kleintje (zo noem ik je) je bent 7 weken
en 6,5 millimeter, onvoorstelbaar dat je nu al jouw hartje kunt zien kloppen.
De vermoedelijke bevallingsdatum wordt op 9 oktober 2005 vastgesteld, Tjonge
wat klinkt dat nog ver weg. De energie voor 10 was van korte duur, veel slaap
is ervoor in de plaats gekomen, 's avonds om acht uur rol ik om van de slaap.
Gekke gewoonte: waterijs, ik kan er niet vanaf blijven, spekjes en zuurtjes.
Waar ik een hekel aan heb gekregen, kip snijden en bakken en de geur van
wokolie. Bah, wat smerig.
Appelgebak
Met appelgebak zijn we naar jouw opa Mans en oma Marie gegaan. Ze zijn blij
voor ons en ik hoop dat je veel plezier zult hebben met je opa Mans en oma
Marie zodra je bent geboren. Nu nog opa Jan en Dagmar vertellen dat je op
komst bent
What did I misunderstood ?
Roelof
----------------------------------------
From: Robby(_dot_)Pelssers(_at_)nxp(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: Mon, 21 Nov 2011 20:25:07 +0100
Subject: RE: [xsl] Can grouping here the solution ?
No this will not work...
<xsl:for-each group select="pagenumber eq page" group-by="page" >
</xsl:for-each-group>
<!-- first of all you are using a Boolean expression in your select clause
whereas you want to use a predicate which in this case would be
Select="page[your predicate]"
But you are really not interested in having just groups of pagenumbers. You
want to have groups of entries so it still needs to be
<!-- now the select expression depends on the context but assuming you are
inside the parent 'display-articles' matching template then you can do
something like -->
<xsl:param name="pageNumber"/>
<xsl:template match="display-articles">
<xsl:for-each-group select="entry" group-by="page">
<!-- only handle grouped entries if the grouping-key which is page equals
our page parameter -->
<xsl:if test="current-grouping-key() eq $pageNumber">
<xsl:apply-templates select="current-group()"/> <!-- we tell the processor
to continue handling the entries of THIS (current) group.
</xsl:if>
</xsl:for-each-group>
</xsl:template>
<xsl:template match="entry">
<!-- here is where you want to do the heavy lifting and transforming your
entries -->
</xsl:template>
Hope this gives a bit of insight,
Robby
-----Original Message-----
From: Roelof Wobben [mailto:rwobben(_at_)hotmail(_dot_)com]
Sent: Monday, November 21, 2011 8:14 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Can grouping here the solution ?
Hello,
Supposed I only want to check the page number.
Can this then work.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml" version="2.0 />
<xsl:variable name="page"/> <!-- this has to be filled with the value of
page in the xml file -->
<xsl:variable name="pagenumber /> <! on some way I have this to fill with
the url paramater @value which contains the 2005-02 --->
xsl:for-each group select="pagenumber eq page" group-by="page" />
<!-- Do display here -->
<xsl: for-each />
Roelof
From: Robby(_dot_)Pelssers(_at_)nxp(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: Mon, 21 Nov 2011 19:10:15 +0100
Subject: RE: [xsl] Can grouping here the solution ?
Ok Ken, thx for the advice. I actually never used to do so but at some
point in time I figured it would express more clearly the intent. I guess
I should just always assume this by default to safe on typing.
-----Original Message-----
From: G. Ken Holman [mailto:gkholman(_at_)CraneSoftwrights(_dot_)com]
Sent: Monday, November 21, 2011 6:52 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com;
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Can grouping here the solution ?
In all of my professional work with XSLT I have very rarely ever had
to address text() nodes individually.
At 2011-11-21 18:41 +0100, Robby Pelssers wrote:
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
In your example above where you have "datum/text()" and
"page/text()", you are better served by using simply "datum" and "page".
Consider if your user has the following:
<datum>2003<!--OCR read this '3' as an '8'-->-05-02</datum>
The expression "substring(datum,6,2)" evaluates as "05" as expected.
The expression "substring(datum/text(),6,2)" triggers a runtime error
because of supplying more than one node for the first argument.
Remember in XPath that the value of an element is the concatenation
of that element's descendent text nodes.
I tell my students if they ever think they need to address a text
node directly, to think again because they probably don't.
I hope this is helpful.
. . . . . . . . . . Ken
--
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(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
<Prev in Thread] |
Current Thread |
[Next in Thread>
|
- RE: [xsl] Can grouping here the solution ?, (continued)
- RE: [xsl] Can grouping here the solution ?, G. Ken Holman
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- Message not available
- RE: [xsl] Can grouping here the solution ?, G. Ken Holman
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
- RE: [xsl] Can grouping here the solution ?,
Robby Pelssers <=
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
- Re: [xsl] Can grouping here the solution ?, David Carlisle
- RE: [xsl] Can grouping here the solution ?, Robby Pelssers
- RE: [xsl] Can grouping here the solution ?, Echlin, Robert
- Re: [xsl] Can grouping here the solution ?, David Carlisle
- RE: [xsl] Can grouping here the solution ?, Emma Burrows
- Re: [xsl] Can grouping here the solution ?, Wendell Piez
- Re: [xsl] Can grouping here the solution ?, Michael Kay
- RE: [xsl] Can grouping here the solution ?, Roelof Wobben
|
|
|