Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 08:49 AM
R. Heydenreich
Guest
 
Posts: n/a
Default counting equal entries

Hi all,
I try to create an index page from a document. The idea behind is to
collect a certain word and list it with *all* occurences in the
document, like

foo .... 12, 23, 45
bar .... 2, 5, 88

and so on. I have a XML document which contains entries with different
classes (Java classes).
I have a XSL stylesheet which collects all entries in a sorted order.
But there is one separate entry for each occurence:

foo ... 12
foo ... 23
foo ... 45
bar ... 2

and so on.

Code follows:

<xsl:for-each select="key('index-key', $lower-alphabet)">
<xsl:sort select="@name" case-order="lower-first"/>
<xsl:call-template name="display-index-item">
<xsl:with-param name="item" select="." />
</xsl:call-template>
</xsl:for-each>

The $lower-alphabet is only a variable containing all lower letters.
How can I pass an indicator to the template "display-index-item" where
I can decide if an entry has the same name as the previous one?

TIA,
Ralf.
  #2  
Old July 20th, 2005, 08:50 AM
Joris Gillis
Guest
 
Posts: n/a
Default Re: counting equal entries

> I try to create an index page from a document. The idea behind is to[color=blue]
> collect a certain word and list it with *all* occurences in the
> document, like
>
> foo .... 12, 23, 45
> bar .... 2, 5, 88
>
> and so on. I have a XML document which contains entries with different
> classes (Java classes).
> I have a XSL stylesheet which collects all entries in a sorted order.
> But there is one separate entry for each occurence:
>
> foo ... 12
> foo ... 23
> foo ... 45
> bar ... 2[/color]

Hi,

I'm not sure if this will solve the problem, but you might look at this:

Given this xml:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<occ name="foo" line="23"/>
<occ name="foo" line="12"/>
<occ name="bar" line="5"/>
<occ name="bar" line="88"/>
<occ name="foo" line="45"/>
<occ name="bar" line="2"/>
</root>

#########################
,this stylsheet:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="index-key" match="occ" use="@name"/>

<xsl:template match="/">
<xsl:for-each select="//occ[generate-id(.)=generate-id(key('index-key',@name))]/@name">
<xsl:sort select="." case-order="lower-first"/>
<xsl:value-of select="."/>:
<xsl:apply-templates select="//occ[@name=current()]">
<xsl:sort select="@line" case-order="lower-first"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>

<xsl:template match="occ">
<xsl:value-of select="@line"/>,
</xsl:template>

</xsl:stylesheet>
########################
,will output:

bar: 2, 5, 88, foo: 12, 23, 45,


########################
Is this of any use?

--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
  #3  
Old July 20th, 2005, 08:50 AM
R. Heydenreich
Guest
 
Posts: n/a
Default Re[2]: counting equal entries

"Joris Gillis" <roac@pandora.be> wrote in message news:<opsgqqiv0cyf9v9r@news.pandora.be>...[color=blue]
> [...]
> ########################
> Is this of any use?[/color]

Oh yes, thank you!

Ralf.
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles