Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. .NET DataSet -> Xml + XSLT -> HTML

.NET DataSet -> Xml + XSLT -> HTML

Scheduled Pinned Locked Moved XML / XSL
xmltutorialcsharphtmlhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dratti
    wrote on last edited by
    #1

    Hi all, I'm trying to convert a .NET DataSet into something viewable by a webbrowser. Its trivial to get the dataSet into XML format (.WriteXML), and then I need to transform that with an XSLT transformation. The problem is, the dataset comes back as xml like this: ... ADD_ADZIP164116PROCEDURE2003-06-19T14:08:03.0000000-04:002003-06-19T14:10:19.0000000-04:001998-12-22:11:10:19VALID ADD_LABEL164202FUNCTION2003-06-19T14:08:11.0000000-04:002003-06-19T14:10:20.0000000-04:001998-12-22:11:10:20INVALID ... Which is fine but I get lost when it comes to transforming this data with an XSLT file. The problem is I need to know the element names (OBJECT_NAME, OBJECT_ID, etc) for the html file, but I do not want to hard-code these names into my .xslt file, nor do I wish to generate one on the fly. To give you some more background: All this app does is select some rows from a user defined table and outputs them to some files (CVS, tab delimited, and xml/html). The html is nothing fancy, I just want to dump them into a standard html table that is viewable in a browser, with field names at the top and data beneath it. This doesnt seem like it should be too hard to do. Every example of XSLT Ive seen is very clear and straightforward, I just havent been able to find anything about grabbing an elements name, and Im not sure how to change the format of the XML given by the dataset (which would be another solution - if I just formatted the xml differently). Any suggestions? Thanks Dave Ratti

    P 1 Reply Last reply
    0
    • D dratti

      Hi all, I'm trying to convert a .NET DataSet into something viewable by a webbrowser. Its trivial to get the dataSet into XML format (.WriteXML), and then I need to transform that with an XSLT transformation. The problem is, the dataset comes back as xml like this: ... ADD_ADZIP164116PROCEDURE2003-06-19T14:08:03.0000000-04:002003-06-19T14:10:19.0000000-04:001998-12-22:11:10:19VALID ADD_LABEL164202FUNCTION2003-06-19T14:08:11.0000000-04:002003-06-19T14:10:20.0000000-04:001998-12-22:11:10:20INVALID ... Which is fine but I get lost when it comes to transforming this data with an XSLT file. The problem is I need to know the element names (OBJECT_NAME, OBJECT_ID, etc) for the html file, but I do not want to hard-code these names into my .xslt file, nor do I wish to generate one on the fly. To give you some more background: All this app does is select some rows from a user defined table and outputs them to some files (CVS, tab delimited, and xml/html). The html is nothing fancy, I just want to dump them into a standard html table that is viewable in a browser, with field names at the top and data beneath it. This doesnt seem like it should be too hard to do. Every example of XSLT Ive seen is very clear and straightforward, I just havent been able to find anything about grabbing an elements name, and Im not sure how to change the format of the XML given by the dataset (which would be another solution - if I just formatted the xml differently). Any suggestions? Thanks Dave Ratti

      P Offline
      P Offline
      Philip Fitzsimons
      wrote on last edited by
      #2

      use need to use the name() function in xslt. In order to not hard code element names you should pass them as parameters to your xslt. so something like: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0" >   <xsl:param name="column_name">object_NAME</xsl:param>   <xsl:template match="/">     <xsl:value-of select="//table/*[name() = $column_name]/text()"&/>   </xsl:template> </xsl:stylesheet> if you don't pass a parameter to your xslt, then it will default to 'object_NAME'. c# calling code: XslTransform xslt = new XslTransform(); XmlDocument document = new XmlDocument(); document.LoadXml(xmlFileName); xslt.Load(stylesheetFileName); MemoryStream ms = new MemoryStream(); XPathNavigator nav = document.CreateNavigator(); XsltArgumentList xslArg = new XsltArgumentList(); xslArg.AddParam("column_name", "", "**name of column you want**"); xslt.Transform(nav, xslArg, ms, null); // output to a stream StreamReader sr = new StreamReader(ms); ms.Position = 0; string result = sr.ReadToEnd(); sr.Close();


      "When the only tool you have is a hammer, a sore thumb you will have."

      D 1 Reply Last reply
      0
      • P Philip Fitzsimons

        use need to use the name() function in xslt. In order to not hard code element names you should pass them as parameters to your xslt. so something like: <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   version="1.0" >   <xsl:param name="column_name">object_NAME</xsl:param>   <xsl:template match="/">     <xsl:value-of select="//table/*[name() = $column_name]/text()"&/>   </xsl:template> </xsl:stylesheet> if you don't pass a parameter to your xslt, then it will default to 'object_NAME'. c# calling code: XslTransform xslt = new XslTransform(); XmlDocument document = new XmlDocument(); document.LoadXml(xmlFileName); xslt.Load(stylesheetFileName); MemoryStream ms = new MemoryStream(); XPathNavigator nav = document.CreateNavigator(); XsltArgumentList xslArg = new XsltArgumentList(); xslArg.AddParam("column_name", "", "**name of column you want**"); xslt.Transform(nav, xslArg, ms, null); // output to a stream StreamReader sr = new StreamReader(ms); ms.Position = 0; string result = sr.ReadToEnd(); sr.Close();


        "When the only tool you have is a hammer, a sore thumb you will have."

        D Offline
        D Offline
        dratti
        wrote on last edited by
        #3

        Great, thanks. One more question - what if I dont know how many columns the table is going to have? I think I might be able to hack something together with mxlns:script, unless anyone has a better idea? Thanks Dave Ratti

        P 1 Reply Last reply
        0
        • D dratti

          Great, thanks. One more question - what if I dont know how many columns the table is going to have? I think I might be able to hack something together with mxlns:script, unless anyone has a better idea? Thanks Dave Ratti

          P Offline
          P Offline
          Philip Fitzsimons
          wrote on last edited by
          #4

          as you guessed you will have to scripting to do this - version 1 of xsl is pretty bare bones...


          "When the only tool you have is a hammer, a sore thumb you will have."

          D 1 Reply Last reply
          0
          • P Philip Fitzsimons

            as you guessed you will have to scripting to do this - version 1 of xsl is pretty bare bones...


            "When the only tool you have is a hammer, a sore thumb you will have."

            D Offline
            D Offline
            dratti
            wrote on last edited by
            #5

            Ok, thanks for your time; you were very helpful Dave ratti

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups