Copied to clipboard

Flag this post as spam?

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


  • Walter E. Harms 13 posts 33 karma points
    Dec 23, 2009 @ 15:35
    Walter E. Harms
    0

    Getting Unique years from date field

    Hi, 2010 is coming so the website of out local fire department (www.brandweerkoudekerk.nl) needs a update. A new years has to be added.. But.. What is the best way to do this with XSLT;

    I have a list of nodes all containing a date field, i want to get a list with all unique years (for navigation purposes offcourse).

    Thanks for any suggestions.

     

    Walter

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Dec 24, 2009 @ 09:19
    Richard Soeteman
    0

    Hi Walter,

    I had a similar request earlier this year (list of keywords) and ended up writing an XSLT Extension for that. Get all the news nodes and get the date property from that add the unique years to an xml document and return that as a XpathNodeIterator what you can use in your xslt again. The example below shows you how to build an xml fragment and returns that as an XpathNodeIterator

     

    public static XPathNodeIterator GetTextInfo(string applicationName, string locale, string context)

    {

     

    XPathNodeIterator result = null;

     

    string xpath = string.Format("//node[@nodeTypeAlias = 'TextContentRoot']/node[data [@alias='nodeNameToLower'] ='{0}']/node[@nodeTypeAlias = 'TextItem' and data [@alias='nodeNameToLower'] = '{1}'] ", applicationName.ToLower(), context.ToLower());

     

    Node node = GetResult(xpath);

     

    if (node != null)

    {

     

    string title = GetPropertyValue(node.GetProperty(string.Format("{0}_Title", locale)));

     

    string text = GetPropertyValue(node.GetProperty(string.Format("{0}_Text", locale)));

     

    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.AppendChild(xmlDoc.CreateElement(

    "TextInfo"));

     

    XmlNode titleNode = xmlDoc.CreateElement("title");

    titleNode.InnerText = title;

     

    XmlNode textNode = xmlDoc.CreateElement("text");

    textNode.InnerText = text;

    xmlDoc.DocumentElement.AppendChild(titleNode);

    xmlDoc.DocumentElement.AppendChild(textNode);

    result = xmlDoc.CreateNavigator().Select(

    "//TextInfo");

    }

     

    return result;

    }

    Then you can configure the xslt Extension as described in this blogpost. While writing this reply I was looking for more concrete examples but couldn't findi those. Could be the first Blogpost/WIKI page for 2010 :-) 

     I've seen some post on how to do that with 100% pure XSLT but I couldn't read that code ;-)

    Hope this puts you in the right direction.

    Cheers,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft