Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

xml to html Expand / Collapse
Author
Message
Posted Friday, January 03, 2014 8:55 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 4:52 AM
Points: 115, Visits: 138
Hi,

I'm working on a script at the moment that pulls groups of data out with each group represented as xml data.
I'd like to transform the xml using a stylesheet into html then output the html as a table using a sql script.

Is there any good tutorials out there that someone can recommend.

Any help welcome on this.

Thanks,
Eamon
Post #1527588
Posted Friday, January 03, 2014 9:46 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,418, Visits: 1,565
Hi,
If you want to use a stylesheet then your options are going to be limited if you want to keep it all inside sql. SSIS supports xsl transformations via the XML task, although I have rarely used this myself so can't really advise on that http://technet.microsoft.com/en-us/library/ms141055.aspx.

SQL CLR is another option if you are able/want to head in that direction.

How complicated is the HTML that you are generating via the stylesheet? As if it is fairly simple, then in theory you could build the html on the fly using t-sql without the need to use a stylesheet.

If you could provide some examples of what the resultant html needs to look like and describe your source table structures then that might help. how is the resultant html going to be consumed?

Personally unless this is only going to be used on an ad-hoc type basic I'd be inclined to move the html generation into an application tier rather than getting sql to generate the HTML itself on a regular basis.
Post #1527629
Posted Friday, January 03, 2014 10:06 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, April 08, 2014 4:52 AM
Points: 115, Visits: 138
Thanks for this.

I kind of expected a reply like this as I've looked around quite a bit and always ended up with CLR or SSIS offering a solution.
Building the html on the fly I think is my best option here as the output is quite basic with only 4 columns of data.
I have already played around with and works just fine.

I very appreciate you advice and quick reply.

Kind regards,
Eamon
Post #1527638
Posted Wednesday, January 08, 2014 1:41 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 2:02 PM
Points: 500, Visits: 2,291
I know this is a few days old but I thought it would be good to expand on this a little:

The W3C defines two technologies for "Transforming XML": SQLXML/XQuery and XSLT
A limited version of XQuery is available in XML but, as arthurolcot mentioned, it would likely do the trick (especially if you are dealing with 4 simple columns). XML Transforms (XSLT) are the more elegant way to go IMHO but the only way to run XSLT is via SSIS or SQLCLR.

On that note, if you go the SQLCLR route you can use mdq.xmltranform (a CLR written by Microsoft) to transform XML to HTML. You can also build an XSLT CLR from scratch but mdq.xmltransform has already been compiled and takes one minute to setup (no need to create a new DLL). I wrote a couple articles about how to do transforms in SQL Server. mdq.xmltransform will be slower than using XQuery but it will work and the code will be 99.9% portable. Doing the transforms using SSIS will perform butter (but will also require you to be comfortable with SSIS which not everone is).

A few good sites about transforming XML using XSLT:
http://w3schools.com/xpath/default.asp
http://w3schools.com/xsl/default.asp
http://www.xml.com/pub/a/2000/08/holman/index.html?page=5#sample1



Edit: Added note about not needing to compile a dll for the CLR


-- Alan Burstein



Read this article for best practices on asking questions.
Need to split a string? Try this (Jeff Moden)
Need a pattern-based string spitter? Try this (Dwain Camps)
My blog
Post #1529092
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse