473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XSL grouping (Muenchian)

Greetings.

I have a question involving sorting and grouping output using XSLT. I am
trying to produce a publication list from a BibTeX-like XML file:

<bibxml:file xmlns:bibxml="http://bibtexml.sf.net/">

<bibxml:entry id="foo01">
<bibxml:article>
<bibxml:title>Foo</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:article>
</bibxml:entry>

<bibxml:entry id="foo02">
<bibxml:book>
<bibxml:title>Baz</bibxml:title>
<bibxml:year>1999</bibxml:year>
</bibxml:book>
</bibxml:entry>

<bibxml:entry id="foo03">
<bibxml:inproceedings>
<bibxml:title>Bar</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:inproceedings>
</bibxml:entry>

</bibxml:file>

I want the output to be as follows:

YEAR 1999:
Baz

YEAR 2001:
Bar
Foo

A naive adaptation of the example at
<http://www.jenitennison.com/xslt/grouping/muenchian.html> results in the
following:

<xsl:key name="entries-by-year" match="bibxml:entry" use="bibxml:year" />
<xsl:template match="bibxml:file">
<xsl:for-each select="contact[count(. | key('entries-by-year',
bibxml:year)[1]) = 1]">
<xsl:sort select="bibxml:year" />
YEAR <xsl:value-of select="bibxml:year" />:
<xsl:for-each select="key('entries-by-year', bibxml:year)">
<xsl:sort select="bibxml:title" />
<xsl:value-of select="bibxml:title" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>

The problem is that in my case the bibxml:year element is not a direct
child of bibxml:entry, but rather inside some other element (which could
be bibxml:article, bibxml:book, or any of a number of others). Could
someone suggest to this XSLT newbie what I need to change in the above
XSLT code to account for this?

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Jul 20 '05 #1
2 2717
Tempore 12:42:20, die Monday 31 January 2005 AD, hinc in foro {comp.text.xml} scripsit Tristan Miller <ps********@nothingisreal.com>:
<bibxml:file xmlns:bibxml="http://bibtexml.sf.net/">

<bibxml:entry id="foo01">
<bibxml:article>
<bibxml:title>Foo</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:article>
</bibxml:entry>

<bibxml:entry id="foo02">
<bibxml:book>
<bibxml:title>Baz</bibxml:title>
<bibxml:year>1999</bibxml:year>
</bibxml:book>
</bibxml:entry>

<bibxml:entry id="foo03">
<bibxml:inproceedings>
<bibxml:title>Bar</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:inproceedings>
</bibxml:entry>

</bibxml:file>

I want the output to be as follows:

YEAR 1999:
Baz

YEAR 2001:
Bar
Foo
The problem is that in my case the bibxml:year element is not a direct
child of bibxml:entry, but rather inside some other element (which could
be bibxml:article, bibxml:book, or any of a number of others). Could
someone suggest to this XSLT newbie what I need to change in the above
XSLT code to account for this?

Regards,
Tristan

Hi,
Try something like this:

<xsl:key name="entries-by-year" match="bibxml:entry" use="*/bibxml:year" />

<xsl:template match="bibxml:file">
<xsl:for-each select="bibxml:entry[count(. | key('entries-by-year',*/bibxml:year)[1]) = 1]">
<xsl:sort select="*/bibxml:year" />
YEAR <xsl:value-of select="*/bibxml:year" />:
<xsl:for-each select="key('entries-by-year',*/bibxml:year)">
<xsl:sort select="*/bibxml:title" />
<xsl:value-of select="*/bibxml:title" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2
Tristan Miller wrote:
Greetings.

I have a question involving sorting and grouping output using XSLT. I am
trying to produce a publication list from a BibTeX-like XML file:

<bibxml:file xmlns:bibxml="http://bibtexml.sf.net/">

<bibxml:entry id="foo01">
<bibxml:article>
<bibxml:title>Foo</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:article>
</bibxml:entry>

<bibxml:entry id="foo02">
<bibxml:book>
<bibxml:title>Baz</bibxml:title>
<bibxml:year>1999</bibxml:year>
</bibxml:book>
</bibxml:entry>

<bibxml:entry id="foo03">
<bibxml:inproceedings>
<bibxml:title>Bar</bibxml:title>
<bibxml:year>2001</bibxml:year>
</bibxml:inproceedings>
</bibxml:entry>

</bibxml:file>

I want the output to be as follows:

YEAR 1999:
Baz

YEAR 2001:
Bar
Foo

A naive adaptation of the example at
<http://www.jenitennison.com/xslt/grouping/muenchian.html> results in the
following:

<xsl:key name="entries-by-year" match="bibxml:entry" use="bibxml:year" />
<xsl:template match="bibxml:file">
<xsl:for-each select="contact[count(. | key('entries-by-year',
bibxml:year)[1]) = 1]">
<xsl:sort select="bibxml:year" />
YEAR <xsl:value-of select="bibxml:year" />:
<xsl:for-each select="key('entries-by-year', bibxml:year)">
<xsl:sort select="bibxml:title" />
<xsl:value-of select="bibxml:title" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>

The problem is that in my case the bibxml:year element is not a direct
child of bibxml:entry, but rather inside some other element (which could
be bibxml:article, bibxml:book, or any of a number of others). Could
someone suggest to this XSLT newbie what I need to change in the above
XSLT code to account for this?

Regards,
Tristan


hi,

try this:
<xsl:key name="entries-by-year" match="bibxml:entry"
use="bibxml:*/bibxml:year" />

if the parent of bibxml:year may be bound to another namespace, simply use:
*/bibxml:year

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bryce (Work) | last post by:
Here is the xml I'm working with: <result> <EFORM> <testNode> <section1> <string1>ADAM</string1> <integer1>55</integer1> </section1> </testNode>
3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
5
by: Jody Greening | last post by:
Transforming with XSLT, Grouping elements until difference found. I am seeking some help with the following problem, I am fairly new at XSLT transformations, and my problem may lie in looking at...
4
by: kristofera | last post by:
I am trying to do a distinct grouping of some nodes sorted by a numeric value but for some reason the distinct (preceding-sibling filter) is applied to the result as if not sorted. If I don't use...
6
by: Per Jørgen Vigdal | last post by:
I have a XML that I need to map. The XML goes like: <Children> <Child> <References> <External> <Reference name="filename" value="1.dat"/> <Reference name="invoicenr" value="1111111"/>...
1
by: rayt | last post by:
I’m relatively new to XSLT and must admit I’m finding it refreshing, but every now and again something comes along which floors me. Maybe it’s the old imperative language background that is hard to...
2
by: Andreas Håkansson | last post by:
Seeing how my previous post seem to have fallen between the cracks, I thought I would have a second, more direct, go at it. So my question is "Is it possible to group (Muenchian method) over...
1
by: lennyw | last post by:
Hi I'm trying to use XSLT to do an xml to xml transformation where the output xml contains summary data on the information in the input xml. I've succesfully done a Muenchian grouping of the...
1
by: Sandeep Singh | last post by:
Hi, How to do group by in XSLT ? I tried on the following codes: <files> <file name="swablr.eps" size="4313" project="mars"/> <file name="batboy.wks" size="424" ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.