x First time here? Check out the FAQ

Come work for Umbraco - The Umbraco HQ are hiring Project managers, .NET developers and DevOps people!

  • Avatar100posts125karma

    how to query datatable return from xsltextension in xslt

    praveity started this topic April 5, 2011 @ 11:29, Go directly to the topic solution

    Hi to all,

    I am trying to develop a xslt extension which returns datable. The datatable consists of two columns like

    col A and col B. I would like to populate colA based on colB value.

    How could I do this in xslt??

    Is it possible to have datatable as return value in xslt??


  • Ismail Mayat posted this reply April 5, 2011 @ 01:11

    praverity,

    xslt extensions return xpathnavigator or simple types like string integer etc you cannot return a datatable. You can create xml representation of your data and return that as xpathnavigator.

    Regards

    Ismail


  • Avatar100posts125karma
    Comment with ID: 72664
    praveity posted this reply April 5, 2011 @ 01:34

    Ismail

    Thanks for your earlier reply. 

    I will work on it and let you know.


  • Avatar100posts125karma
    Comment with ID: 72799
    praveity posted this reply April 6, 2011 @ 08:44

    I found the solution. Here is the code snipet 

     

    private XPathNavigator getTagCloud()
        {
            var sqlHelper = DataLayerHelper.CreateSqlHelper(umbraco.GlobalSettings.DbDSN);
            umbraco.DataLayer.IRecordsReader resultSet = sqlHelper.ExecuteReader("select * from tagcloud");
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.CreateElement("Tags");
            XPathNavigator nav;
            doc.AppendChild(root);
            if (resultSet.HasRecords)
            {
                while (resultSet.Read())
                {
                    XmlElement ele = doc.CreateElement("Tag");
                    ele.SetAttribute("id", resultSet.GetInt("Id").ToString());
                    ele.SetAttribute("value", resultSet.GetString("value"));
                    ele.SetAttribute("hitCount", resultSet.GetInt("hitCount").ToString());
                    root.AppendChild(ele);
                }
                nav = doc.CreateNavigator();
                return nav;
            }
            else
            {  
                return doc.CreateNavigator();        
            }
            
        }

    Then in xslt i have

    <xsl:for-each select="TagCloudHelper:GetTagCloud(10)/descendant-or-self::Tag">
    <xsl:value-of select="@value"/>
    <xsl:value-of select="@hitCount"/>

    </xsl:for-each>

    Now I could use the whole table values in my xslt. 

    Hope this help.

    Thanks

     


Please login or Sign up To post replies