Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • sentana 3 posts 20 karma points
    Mar 11, 2009 @ 21:04
    sentana
    0

    XSLT count distinct values

    I am new to xslt,i tried to get the distinct years and the corresponding number of publications
    for eg


    Year Number of publication

    2008 6
    2009 4

    I am using Xpath 1.0

    I managed to get the date value changed to the above format but then to count the number of publication it makes my mind to blow
    The Xslt which converts the date
    $





    This is my Xml file






    Thankyou for your help.






















  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 11, 2009 @ 21:21
    Morten Bock
    0

    Take a look at this blogpost:
    http://www.bernzilla.com/item.php?id=333

    The xsl:key element is what you need to dig into.

  • Tommy Poulsen 514 posts 708 karma points
    Mar 11, 2009 @ 23:23
  • sentana 3 posts 20 karma points
    Mar 12, 2009 @ 16:28
    sentana
    0

    Thankyou guys,i think Xslt key is an interesting logic to solve the problem,even though i couldn't manage it till now. I spend hours but ,it makes me crazy.

    Tommy ,can you please post some solution specific to my problem please?
    I am now having two things
    1. Get the distinct values
    2.Count the number of occurrences of the year only like

    2008 6 occurrences

    2009 4


    Thanks in advance

  • sentana 3 posts 20 karma points
    Mar 12, 2009 @ 20:30
    sentana
    0

    Thank you Tommy and Århus

    I did it with 2 methods
    1. By Substring method http://bytes.com/groups/xml/86180-tip-finding-counting-unique-nodes-xsl
    2. Key and id

    Both are interesting solutions .

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 12, 2009 @ 21:05
    Morten Bock
    0

    My complete xslt. Note that I am using ns0 prefixes to satisfy the namespace on the root node.

    [code]

    <>
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:ns0="http://www.loc.gov/mods/v3"
    exclude-result-prefixes="msxsl ns0">







    [/code]

  • sentana 3 posts 20 karma points
    Mar 12, 2009 @ 21:28
    sentana
    0

    Thankyou Århus,that is excellent.

    I did it like this:- My next step is to draw a java script chart which shows the number of publication as Bars and X axis will be years, if you recommend me some thing it will be excellent.


    version='1.0'>















    Year

    Count of Publication





Please Sign in or register to post replies

Write your reply to:

Draft