x First time here? Check out the FAQ
  • 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??

  • Avatar3317posts6259karma2015 MVP
    adminMVPSolutionComment with ID: 72661
    Ismail Mayat posted this reply April 5, 2011 @ 01:11


    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.



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


    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;
            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());
                nav = doc.CreateNavigator();
                return nav;
                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"/>


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

    Hope this help.



Please login or Sign up To post replies