counting equal entries

Discussion in 'XML' started by R. Heydenreich, Oct 28, 2004.

  1. 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.
    R. Heydenreich, Oct 28, 2004
    #1
    1. Advertising

  2. R. Heydenreich

    Joris Gillis Guest

    > 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


    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:eek:utput 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-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
    Joris Gillis, Oct 31, 2004
    #2
    1. Advertising

  3. Re[2]: counting equal entries

    "Joris Gillis" <> wrote in message news:<>...
    > [...]
    > ########################
    > Is this of any use?


    Oh yes, thank you!

    Ralf.
    R. Heydenreich, Nov 1, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ron Vecchi

    Need to make control equal to control

    Ron Vecchi, Dec 11, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    431
    Jacob Yang [MSFT]
    Dec 12, 2003
  2. Ralph Krausse

    ALL 'try/catch/finally' NOT created equal?

    Ralph Krausse, Aug 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    406
  3. Stormbringer
    Replies:
    11
    Views:
    500
    Bengt Richter
    Dec 23, 2003
  4. Don Bruder
    Replies:
    3
    Views:
    949
    spikeysnack
    Aug 3, 2010
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    186
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page