TODO: Create an XSLT Extension to show data on Front End

Coordinator
May 11, 2010 at 10:53 PM

Since the value is stored in the databse as an XML string, an XSLT extension is required to convert to an HTML table on the Front End.

Developer
May 12, 2010 at 6:17 AM

Can't you just use a normal XSLT file instead of an XSLT extension? If the XML is stored as a property in the database (in the cmsPropertyData table) it is also stored inside the umbraco.config file. No XSLT extension is required if it's stored inside the umbraco.config XML. The Tribal XPath node relations package does the same thing with a normal XSLT file.

Coordinator
May 12, 2010 at 7:36 AM
Sounds like a good idea, but I'm pretty new to xslt. Keen to write it?
Developer
May 12, 2010 at 10:30 PM

A file is definitely the way to go - users of this DataType will almost always have to do some sort of modification to suit client needs.

Also, I'd be happy to help writing the actual XSLT if you'd like some help in that area.

Coordinator
May 12, 2010 at 11:28 PM
Edited May 12, 2010 at 11:29 PM

Thanks @greystate, I'll add you as a Developer if you'd like to contribute to the project and help with the XSLT.

Here's an example of the XML that gets written to the umbraco.config file

 

<data alias="dimensions"><![CDATA[&lt;NewDataSet&gt;&lt;Dimensions&gt;&lt;Column1&gt;Desk&lt;/Column1&gt;&lt;Width&gt;1200mm&lt;/Width&gt;&lt;
Height&gt;600mm&lt;/Height&gt;&lt;Depth&gt;800mm&lt;/Depth&gt;&lt;/Dimensions&gt;&lt;Dimensions&gt;&lt;Column1&gt;Chair&lt;/Column1&gt;&lt;
Width&gt;500mm&lt;/Width&gt;&lt;Height&gt;1200mm&lt;/Height&gt;&lt;Depth&gt;800mm&lt;/Depth&gt;&lt;/Dimensions&gt;&lt;/NewDataSet&gt;
]]></data>

 

 

Developer
May 14, 2010 at 11:11 AM

The xml you store in the umbraco.config is now stored as a string. For xslt it would be much easier if you store your data as xml. Here you can find a sample how this can be done: http://www.nibble.be/?p=51

Developer
May 15, 2010 at 10:37 PM

Hi Marko,

I'll second what jbreuer says, and go even further: The CDATA is useless from an XSLT standpoint, because it was never meant to do anything beyond simple string manipulation with raw text. With XML it's very powerful, so take a look at the link he posted. 

Coordinator
May 15, 2010 at 11:49 PM

Thanks for your comments @jbreuer & @greystate.

As far as I know there are 2 ways of creating custom Data Types, via a user control and via the 3/4 classes. i.e. http://www.nibble.be/?p=50

Does this mean I have to re-write the whole control? I believe the link @jbreuer posted is not related to the usercontrol Data Types.

Thanks for your help.

Marko

Developer
May 16, 2010 at 11:21 AM
Hi Marko, The link I posted is for the datatypes with 3/4 classes. It is highly recommanded you rewright your code using this method (otherwise you can't store xml the correct way). Here are 2 links how this can be done: http://www.nibble.be/?p=62 and http://www.nibble.be/?p=50. I have already done this several times. I don't mind doing it if you send me the source code of your user control. My e-mail is j.breuer@gmail.com. I'd be happy to help you :). Jeroen
Coordinator
May 16, 2010 at 11:55 AM

Thanks Jeroen - all the latest source code is here on CodePlex. I'll have a read through those 2 docs and see what I can make of them as it's my first Umbraco DataType.

Cheers - Marko

Developer
May 16, 2010 at 5:49 PM
Hi Marko, I hope you'll succeed in rewriting you package. If you need any help just let me know :). Jeroen
May 17, 2010 at 7:22 AM

Hi Marko. Thank you for your component. I hope you finish him without troubles. I want use him on my website (=.

Sorry for my bad english.

 

Pavel.

Coordinator
May 17, 2010 at 1:15 PM

Hey Jeroen I've sent you an email with some of the issues I've come across.

Pavel - thanks for your interest we should be able to finish it quickly - there isn't much more work left.

Thanks,

Marko

Developer
May 17, 2010 at 1:40 PM

Hi Mark,

I'm sorry but I made an error in my email. It's jbreuer@gmail.com (without the first dot). Could you please send the e-mail again?

Jeroen

Developer
May 17, 2010 at 7:09 PM

Hi Marko,

When you have a sample of the 'real' XML format of the data, let me know and I'll put some XSLT together — I actually don't know where that should go? Will the datatype install a sample macro w/XSLT or how is this normally done for datatypes?

Regarding the actual format of the XML, I'd suggets something like the following (based on the screenshot data on our.umbraco.org):

<data alias="Dimensions">
	<grid>
		<column header="Width" />
		<column header="Height" />
		<column header="Depth" />
		<row header="Product 0">
			<value><![CDATA[Width 0]]></value>
			<value><![CDATA[Height 0]]></value>
			<value><![CDATA[Depth 0]]></value>
		</row>
	</grid>
</data>

 

/Chriztian 

 

Coordinator
May 17, 2010 at 8:56 PM

Hey Jeroen that's OK I've re-sent the email.

@greystate - I'll show you what the output looks like once we fix the outstanding issues - and we can certainly tweak it from there to get the best results.

Thanks both for your help,

Marko

Coordinator
May 17, 2010 at 9:03 PM
greystate wrote:

When you have a sample of the 'real' XML format of the data, let me know and I'll put some XSLT together — I actually don't know where that should go? Will the datatype install a sample macro w/XSLT or how is this normally done for datatypes?

Yes, check out the packages section under "Developer". You can create a package, select the necessary .dll's & Macro's and it copies the .xslt files automatically.

Cheers,

Marko

Developer
May 17, 2010 at 9:20 PM

Yeah - sorry 'bout that. I actually meant that I didn't know where to put it in the source files (codeplex), as I'm unsure whether it should (or could) be installed as an XSLT template in the dropdown when creating XSLT files in the Developer section.

/Chriztian

Coordinator
May 17, 2010 at 9:52 PM

No worries :) I usually create a /xslt folder in the project and put my .xslt files in it. You can actually create the .xslt file through Umbraco and then copy/modify it within the solution.

Marko

May 18, 2010 at 11:09 AM
Edited May 18, 2010 at 11:11 AM
Hi guys. I'm newbie in developing for Umbraco. I tried parse xml from DynamicDataGrid in my xslt, but i fail. Can you tell me where i have mistakes?

XML:
<NewDataSet><Dimensions><Column1>1231</Column1><Width>234</Width><Height>3w4</Height></Dimensions><Dimensions><Column1>123</Column1><Width>213</Width><Height>23324</Height></Dimensions></NewDataSet>

XSLT:
<xsl:for-each select="$currentPage/data [@alias ='SpecificationsTable']/NewDataSet/Dimensions/Column1"> <xsl:value-of select="." /> </xsl:for-each>

Sorry for my bad english =).

Pavel.
Coordinator
May 19, 2010 at 4:22 AM

Hi Pavel, as you know the Data Type is still under development so I wouldn't recommend you use it yet. Once it's completed it will come with a default XSLT file which you'll be able to modify to suit your needs.

Developer
Jan 14, 2011 at 6:28 PM

Hi Marko,

I just implemented "store data as XML" (as opposed to [CDATA}) as well as finish wiring up the datatype to read and write to the db, and a few cosmetic changes. I sent you an email about requesting access to the project

Cheers

Jonathan

Coordinator
Jan 18, 2011 at 8:49 AM

Hi Jonathan and thank you for your emai.

You're more than welcome to contribute your work to the project since I've been absolutely flat out and unable to put more effort into it.

Welcome aboard and let me know if I can be of any assistance.

Cheers,

Marko

Developer
Jan 18, 2011 at 10:04 AM

In Umbraco 4.6 you can do this with usercontrol wrapper aswell so you might not have to rewrite the code. See this sample: http://www.nibble.be/?p=97.

Jeroen

Developer
Feb 11, 2011 at 11:43 PM
I put together an XSLT for my purposes to output from the datagrid in JSON notation. My immediate need is to produce a chart out of the content stored in the database. It's specific to my situation, but I put it here in case anyone else wants to use it as a departure point and adapt it. I'm still hoping to getting around to producing some more XSLTs (or maybe in RAZOR) for more generic use.
Jonathan

<?
xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary" exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:template match="/"> <![CDATA[[]]><!-- Insert "[" --> <xsl:for-each select="$currentPage/dynamicDataGrid/NewDataSet/*"> <!-- Check for bar or Pie chart --> <xsl:if test="umbraco.library:GetPreValueAsString($currentPage/chartType) = 'Bar / Line Chart'" > <!-- One or Two columns of data? --> <xsl:if test="./C1/@caption = 'Actual' and ./C2/@caption != 'Target'"> <xsl:call-template name="barChartData1Col"> <xsl:with-param name="dataSet" select="." /> </xsl:call-template> </xsl:if> <xsl:if test="./C1/@caption = 'Actual' and ./C2/@caption = 'Target'"> <xsl:call-template name="barChartData2Col"> <xsl:with-param name="dataSet" select="." /> </xsl:call-template> </xsl:if> </xsl:if><!-- end bar / line chart --> <xsl:if test="umbraco.library:GetPreValueAsString($currentPage/chartType) = 'Pie Chart'" > <xsl:call-template name="pieChartData"> <xsl:with-param name="dataSet" select="." /> </xsl:call-template> </xsl:if> </xsl:for-each> <![CDATA[]]]><!-- Insert "]" --> </xsl:template> <xsl:template name="barChartData1Col"> <xsl:param name="dataSet" /> <![CDATA[{]]><!-- Insert "{" --> <![CDATA['date': $.datepicker.parseDate('yy,m,d', ']]><xsl:value-of select="$dataSet/C0"/><![CDATA['),]]> <![CDATA['vals': []]><xsl:value-of select="$dataSet/C1"/><![CDATA[],]]> <![CDATA['captions': [']]><xsl:value-of select="$dataSet/C1/@caption"/><![CDATA[']]]> <![CDATA[}]]><!-- Insert "}" --> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> <xsl:template name="barChartData2Col"> <xsl:param name="dataSet" /> <![CDATA[{]]><!-- Insert "{" --> <![CDATA['date': $.datepicker.parseDate('yy,m,d', ']]><xsl:value-of select="$dataSet/C0"/><![CDATA['),]]> <![CDATA['vals': []]><xsl:value-of select="$dataSet/C1"/><![CDATA[,]]><xsl:value-of select="$dataSet/C2"/><![CDATA[],]]> <![CDATA['captions': [']]><xsl:value-of select="$dataSet/C1/@caption"/><![CDATA[',']]><xsl:value-of select="$dataSet/C2/@caption"/><![CDATA[']]]> <![CDATA[}]]><!-- Insert "}" --> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> <xsl:template name="pieChartData"> <xsl:param name="dataSet" /> <![CDATA[{]]><!-- Insert "{" --> <![CDATA['date': ']]><xsl:value-of select="$dataSet/C0"/><![CDATA[',]]> <![CDATA['vals': []]><xsl:value-of select="$dataSet/C1"/><![CDATA[],]]> <![CDATA['captions': [']]><xsl:value-of select="$dataSet/C1/@caption"/><![CDATA[']]]> <![CDATA[}]]><!-- Insert "}" --> <xsl:if test="position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet>