Copied to clipboard

Flag this post as spam?

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


  • praveity 125 karma points
    Apr 05, 2011 @ 11:29
    praveity
    0

    how to query datatable return from xsltextension in xslt

    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 Mayat6539 karma points admin mvp c-trib
    Apr 05, 2011 @ 13:11
    Ismail Mayat
    0

    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

  • praveity125 karma points
    Apr 05, 2011 @ 13:34
    praveity
    0

    Ismail

    Thanks for your earlier reply. 

    I will work on it and let you know.

  • praveity125 karma points
    Apr 06, 2011 @ 08:44
    praveity
    0

    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 Sign in or register to post replies

Write your reply to:

Draft
Our.umbraco.org is the community mothership for Umbraco, the open source asp.net cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community.