Copied to clipboard

Flag this post as spam?

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


  • ayyaz 16 posts 36 karma points
    Apr 01, 2010 @ 13:51
    ayyaz
    0

    Can we use xslt to get umbraco document of specific type having specific value of some specific property in .NET

    can we search or find or query any specific node of some specific type and having some value in its specific property? in .NET code

    e.g some thing like the following in .NET

    $currentPage/ancestor::root/descendant-or-self::node[@nodeTypeAlias='I-Article' and data [@alias='isPressRelease'] = '1']/@id)

    using any  Nodes,   Node , Document classes ?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 01, 2010 @ 15:09
    Jan Skovgaard
    0

    Hi ayyaz

    Yes that is possible. Have a look at the API cheatsheet http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties

    /Jan

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 01, 2010 @ 15:25
    Lee Kelleher
    1

    Hi ayyaz,

    Take a look at Hendy's Umbraco Helper Class, there's a method called "GetNodesFromXpath", which will return a generic List of Node objects. Here's a snippet:

    public static List<Node> GetNodesFromXpath(string xPath)
    {
        List<Node> nodes = new List<Node>();
    
        XPathNavigator xPathNavigator = umbraco.content.Instance.XmlContent.CreateNavigator(); //get all umbraco xml
        XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPath); //TODO: check xpath string is valid
    
        int id;
        Node node;
    
        while (xPathNodeIterator.MoveNext())
        {
            if (int.TryParse(xPathNodeIterator.Current.Evaluate("string(@id)").ToString(), out id)) //check id is a numberic
            {
                node = new Node(id);
                if (node != null) { nodes.Add(node); }
            }
        }
    
        return nodes;
    }

    This way you can use whatever XPath queries you like... and get back a .NET object!

    Cheers, Lee

     

Please Sign in or register to post replies

Write your reply to:

Draft