2.0 solution:
<xsl:for-each-group
select="*[starts-with(name(), 'aabnings')]"
group-adjacent=".">
<xsl:value-of select="concat(
substring-after(name(current-group()[1]), 'aabningstider'),
'-'
substring-after(name(current-group()[last()]), 'aabningstider'),
' ',
current-grouping-key())"/>
</xsl:for-each-group>
Needs a bit of refinement to avoid outputting Man-Man when the group size is
1.
One of the best use cases for group-adjacent I have seen!
In XSLT 1.0, you need to write a recursive template. It's tedious, so I'll
leave it to others.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Verakso [mailto:verakso(_at_)gmail(_dot_)com]
Sent: 06 October 2004 09:56
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Group and compare data
I have som XML that looks like this:
<Forhandler>
<Forhandler>
<navn>Dealer name</navn>
<email>mail(_at_)adress(_dot_)dk</email>
<adresse>road 11</adresse>
<postnr>9999</postnr>
<by>city</by>
<telefon>4444444</telefon>
<aabningstiderMan>7:30 - 17:30</aabningstiderMan>
<aabningstiderTirs>7:30 - 17: 30</aabningstiderTirs>
<aabningstiderOns>7:30 - 17:30</aabningstiderOns>
<aabningstiderTors>7:30 - 17:30</aabningstiderTors>
<aabningstiderFre>7:30 - 17:30</aabningstiderFre>
<aabningstiderLoer>10:00 - 14:00</aabningstiderLoer>
<aabningstiderSoen>Efter aftale</aabningstiderSoen>
</Forhandler>
<Forhandler>
<navn>Another dealer</navn>
<email>another(_at_)adress(_dot_)dk</email>
<adresse>another road</adresse>
<postnr>5555</postnr>
<by>big city</by>
<telefon>5555555</telefon>
<aabningstiderMan>07.30 - 17.30</aabningstiderMan>
<aabningstiderTirs>07.30 - 17.30</aabningstiderTirs>
<aabningstiderOns>07.30 - 17.30</aabningstiderOns>
<aabningstiderTors>07.30 - 17.30</aabningstiderTors>
<aabningstiderFre>07.30 - 16.00</aabningstiderFre>
<aabningstiderLoer>Lukket</aabningstiderLoer>
<aabningstiderSoen>Lukket</aabningstiderSoen>
</Forhandler>
</Forhandler>
What I am trying to accomplish is to group the opening hours so they
look more nice.
For the first dealer the result would be:
Mon-Fre 7:30-17:30
Loer 10:00 - 14:00
Soen Efter aftale
For the second dealer the result would be:
Man-Tor 07.30 - 17.30
Fre 07.30 - 16.00
Loer-Soen Lukket
I have tried som xsl-choose loop, but I went sour in the complexity of
variations, what if a dealer have diffent opening hours every day of
the week.
So I thought, there must be at better approach on how to achieve this.
Is the use of keys a better approach, and if so, how?
/Thomas
--+------------------------------------------------------------------
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>
--+--