- Use it?
- Any good?
- What exactly does it do?
- Is it worth me learning? i.e. What can it be applied to?
- Any personal experience of these books?
XSLT
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
XSLT
Last edited by Ollie Saunders on Mon Aug 28, 2006 5:58 pm, edited 3 times in total.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: XSTL
It has to be said, I've come across more than 1 thread on XSLT (including one that helped me understand something at the time)...ole wrote:I just did a search of these forums and there is only on topic on XSTL and that was just how to install it.
- Use it?
Yes- Any good?
Seemed alright... Very verbose tho'. Turing-complete but some things (drilling down through nested elements to be displayed) is a little more difficult than necessary IMO. The use of 'templates' confused me somewhat at the beginning.- What exactly does it do?
Transform an XML document into (for example) XHTML to be displayed. Basically takes the content which is stored in the XML file and applies a stylesheet to it to display the content and design- Is it worth me learning? i.e. What can it be applied to?
Depends on you, I guess.I'm using it just now, but more as an academic exercise than anything else. I suspect it's probably a little too verbose (combination of XML/XSL[T] means lots of fluff, IMO) for common usage. But with an XML schema, it can be a fairly tight solution for some problems, I think (although none really spring to mind - just generally where you want to store data and it'll need to be a certain layout.
- Any personal experience of these books?
'fraid not
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Basically, XSLT is to XML what CSS on crack would be to XHTML. XSLT can define how XML elements are displayed, but also allows for templates. In a file like this:
...you could set up rules to determine how <displacement> is displayed, as well as set up a template for <tire>. That template would be looped through each <tire> that is found.
Code: Select all
<car>
<displacement>
3.3L
</displacement>
<tire location="driverfront">
<make>
Bridgestone
</make>
</tire>
<tire location = "driverback">
<make>
Firestone
</make>
</tire>
</car>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
Warning, long post, I can host the files if you would prefer...
This is THE best example of what xslt can do (imo at least).
XML:
XSLT:
If that can't show what xslt is capable of, i dont know what could (i also have a stylesheet to turn the xml into mssql queries as well.. same xml, different stylesheet)
Edit: Sorry about that
Queries:
This is THE best example of what xslt can do (imo at least).
XML:
Code: Select all
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="xml2mysql.xsl"?>
<!-- WWWSQLEditor XML export -->
<sql>
<table id="0" title="quotes" x="673" y="131" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="2" nn="nn">
<title>priceMod</title>
<default>0</default>
<type>Single precision</type>
</row>
<row id="3" fk="fk">
<title>clientsId</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn">
<title>internal</title>
<default>0</default>
<type>Byte</type>
</row>
<row id="4" fk="fk">
<title>statusId</title>
<default>0</default>
<type>Integer</type>
</row>
</table>
<table id="1" title="clients" x="440" y="436" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn" special="32">
<title>name</title>
<default></default>
<type>String</type>
</row>
<row id="2" nn="nn" special="75">
<title>address</title>
<default></default>
<type>String</type>
</row>
<row id="3" nn="nn" special="32">
<title>phone</title>
<default></default>
<type>String</type>
</row>
<row id="4" nn="nn" special="32">
<title>fax</title>
<default></default>
<type>String</type>
</row>
<row id="5" nn="nn">
<title>balance</title>
<default>0</default>
<type>Single precision</type>
</row>
</table>
<table id="2" title="itemQuote" x="349" y="170" >
<row id="2" fk="fk">
<title>itemsId</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="0" fk="fk">
<title>quotesId</title>
<default>0</default>
<type>Integer</type>
</row>
</table>
<table id="3" title="items" x="68" y="142" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn" special="32">
<title>name</title>
<default></default>
<type>String</type>
</row>
<row id="2" nn="nn">
<title>avail</title>
<default>0</default>
<type>Byte</type>
</row>
<row id="3" nn="nn">
<title>price</title>
<default>0</default>
<type>Single precision</type>
</row>
<row id="4" nn="nn">
<title>notes</title>
<default></default>
<type>Text</type>
</row>
<row id="5" nn="nn" special="255">
<title>url</title>
<default></default>
<type>String</type>
</row>
<row id="6" fk="fk">
<title>catId</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="7" nn="nn" special="255">
<title>description</title>
<default></default>
<type>String</type>
</row>
<row id="8" fk="fk">
<title>manufId</title>
<default>0</default>
<type>Integer</type>
</row>
</table>
<table id="4" title="categories" x="340" y="288" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn" special="50">
<title>name</title>
<default></default>
<type>String</type>
</row>
<row id="2" nn="nn" special="255">
<title>description</title>
<default></default>
<type>String</type>
</row>
</table>
<table id="5" title="manufacturers" x="62" y="419" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn" special="50">
<title>name</title>
<default></default>
<type>String</type>
</row>
<row id="2" index="index" nn="nn" special="10">
<title>code</title>
<default></default>
<type>String</type>
</row>
<row id="3" nn="nn" special="255">
<title>url</title>
<default></default>
<type>String</type>
</row>
</table>
<table id="6" title="status" x="673" y="337" >
<row id="0" pk="pk" index="index">
<title>id</title>
<default>0</default>
<type>Integer</type>
</row>
<row id="1" nn="nn" special="32">
<title>name</title>
<default></default>
<type>String</type>
</row>
<row id="2" nn="nn">
<title>severity</title>
<default>0</default>
<type>Integer</type>
</row>
</table>
<relation>
<table_1>1</table_1>
<row_1>0</row_1>
<table_2>0</table_2>
<row_2>3</row_2>
</relation>
<relation>
<table_1>3</table_1>
<row_1>0</row_1>
<table_2>2</table_2>
<row_2>2</row_2>
</relation>
<relation>
<table_1>0</table_1>
<row_1>0</row_1>
<table_2>2</table_2>
<row_2>0</row_2>
</relation>
<relation>
<table_1>4</table_1>
<row_1>0</row_1>
<table_2>3</table_2>
<row_2>6</row_2>
</relation>
<relation>
<table_1>5</table_1>
<row_1>0</row_1>
<table_2>3</table_2>
<row_2>8</row_2>
</relation>
<relation>
<table_1>6</table_1>
<row_1>0</row_1>
<table_2>0</table_2>
<row_2>4</row_2>
</relation>
</sql>Code: Select all
<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/sql">
<html>
<body id="body"><pre>
<xsl:for-each select="table">
<xsl:text>CREATE TABLE `</xsl:text>
<xsl:value-of select="@title" />
<xsl:text>` (</xsl:text>
<xsl:for-each select="row">
<xsl:text>`</xsl:text>
<xsl:value-of select="title" />
<xsl:text>` </xsl:text>
<xsl:if test="type = 'Integer'">
<xsl:text>INTEGER</xsl:text>
</xsl:if>
<xsl:if test="type = 'Byte'">
<xsl:text>TINYINT</xsl:text>
</xsl:if>
<xsl:if test="type = 'Single precision'">
<xsl:text>FLOAT</xsl:text>
</xsl:if>
<xsl:if test="type = 'Double precision'">
<xsl:text>DOUBLE</xsl:text>
</xsl:if>
<xsl:if test="type = 'String'">
<xsl:text>VARCHAR</xsl:text>
<xsl:text> (</xsl:text>
<xsl:value-of select="@special" />
<xsl:text>) </xsl:text>
</xsl:if>
<xsl:if test="type = 'Text'">
<xsl:text>MEDIUMTEXT</xsl:text>
</xsl:if>
<xsl:if test="type = 'Binary'">
<xsl:text>VARBINARY</xsl:text>
<xsl:text> (</xsl:text>
<xsl:value-of select="@special" />
<xsl:text>) </xsl:text>
</xsl:if>
<xsl:if test="type = 'BLOB'">
<xsl:text>BLOB</xsl:text>
</xsl:if>
<xsl:if test="type = 'Date'">
<xsl:text>DATE</xsl:text>
</xsl:if>
<xsl:if test="type = 'Time'">
<xsl:text>TIME</xsl:text>
</xsl:if>
<xsl:if test="type = 'Datetime'">
<xsl:text>DATETIME</xsl:text>
</xsl:if>
<xsl:if test="type = 'Timestamp'">
<xsl:text>TIMESTAMP</xsl:text>
</xsl:if>
<xsl:if test="type = 'Enum'">
<xsl:text>ENUM</xsl:text>
<xsl:text> (</xsl:text>
<xsl:value-of select="@special" />
<xsl:text>) </xsl:text>
</xsl:if>
<xsl:if test="type = 'Set'">
<xsl:text>SET</xsl:text>
<xsl:text> (</xsl:text>
<xsl:value-of select="@special" />
<xsl:text>) </xsl:text>
</xsl:if>
<xsl:text> </xsl:text>
<xsl:if test="@nn">
<xsl:text>NOT NULL </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="@pk">
<xsl:text>auto_increment </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>default '</xsl:text>
<xsl:value-of select="default" />
<xsl:text>'</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="not (position()=last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="row">
<xsl:choose>
<xsl:when test="@pk">
<xsl:text>,</xsl:text>
<xsl:text>PRIMARY KEY (`</xsl:text>
<xsl:value-of select="title" />
<xsl:text>`)</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@index">
<xsl:text>,</xsl:text>
<xsl:text>KEY `</xsl:text>
<xsl:value-of select="title" />
<xsl:text>` (`</xsl:text>
<xsl:value-of select="title" />
<xsl:text>`)</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text>);</xsl:text><br/>
</xsl:for-each>
</pre></body>
</html>
</xsl:template>
</xsl:stylesheet>Edit: Sorry about that
Queries:
Code: Select all
CREATE TABLE `quotes` (
`id` INTEGER auto_increment ,
`priceMod` FLOAT NOT NULL default '0',
`clientsId` INTEGER default '0',
`internal` TINYINT NOT NULL default '0',
`statusId` INTEGER default '0',
PRIMARY KEY (`id`)
);
CREATE TABLE `clients` (
`id` INTEGER auto_increment ,
`name` VARCHAR (32) NOT NULL default '',
`address` VARCHAR (75) NOT NULL default '',
`phone` VARCHAR (32) NOT NULL default '',
`fax` VARCHAR (32) NOT NULL default '',
`balance` FLOAT NOT NULL default '0',
PRIMARY KEY (`id`)
);
CREATE TABLE `itemQuote` (
`itemsId` INTEGER default '0',
`quotesId` INTEGER default '0'
);
CREATE TABLE `items` (
`id` INTEGER auto_increment ,
`name` VARCHAR (32) NOT NULL default '',
`avail` TINYINT NOT NULL default '0',
`price` FLOAT NOT NULL default '0',
`notes` MEDIUMTEXT NOT NULL default '',
`url` VARCHAR (255) NOT NULL default '',
`catId` INTEGER default '0',
`description` VARCHAR (255) NOT NULL default '',
`manufId` INTEGER default '0',
PRIMARY KEY (`id`)
);
CREATE TABLE `categories` (
`id` INTEGER auto_increment ,
`name` VARCHAR (50) NOT NULL default '',
`description` VARCHAR (255) NOT NULL default '',
PRIMARY KEY (`id`)
);
CREATE TABLE `manufacturers` (
`id` INTEGER auto_increment ,
`name` VARCHAR (50) NOT NULL default '',
`code` VARCHAR (10) NOT NULL default '',
`url` VARCHAR (255) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `code` (`code`)
);
CREATE TABLE `status` (
`id` INTEGER auto_increment ,
`name` VARCHAR (32) NOT NULL default '',
`severity` INTEGER NOT NULL default '0',
PRIMARY KEY (`id`)
);
Last edited by nickvd on Mon Aug 28, 2006 3:14 pm, edited 1 time in total.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Edit: It appears from the last example of XSLT I was correct in my assumption...in that it allows for advanced meta-language manipulation of a DOM...pickle wrote:Basically, XSLT is to XML what CSS on crack would be to XHTML. XSLT can define how XML elements are displayed, but also allows for templates.
This is what confuses me...displayed in this context is so vague...
My understanding of XML is that it's just a generic data format, which any application can use or read using DOM or SAX.
If you entered a XML like you have inside an HTML browser it wouldn't render anything that special, except if you maybe applied CSS to the elements, then depending on the browser and DOCTYPE, etc...you mmay get boldied text...
My point is...it doesn't exactly make a <person> display as a photo or anyting as XSLT would then require some rendering code...which I wouldn't image it to have...
Soooo...by display...what do you mean???
Like I can convert <family> into <brother><sister><father><mother>
Which basically expanded an existing tag into something more specific?
Or you wuold use XSLT to transform an XML file:
Code: Select all
<html>
<body>
<person name="Alex" age="27">
<person name="Barb" age="23">
</body>
</html>If this is a better example of what is meant by displayed...then...why wouldn't I just use a DOM to manipulate the person tags, createElement(), etc...and generate a displayed programatically? Does XSLT do basically this, but using a meta-language (XSLT syntax) to allow manipulating a DOM easier???
I've always been curious about XSLT...and if the latter is correct, it just clicked
But the output doesn't need to be xml, it might be pdf or plain text or ...what ever you want. And all from the same datasource.Hockey wrote:Edit: It appears from the last example of XSLT I was correct in my assumption...in that it allows for advanced meta-language manipulation of a DOM...
They might, but they don't. Or e.g. does your acrobat reader takes the same html as input as your current browser?Hockey wrote:My understanding of XML is that it's just a generic data format, which any application can use or read using DOM or SAX.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I was aware of that...seriously...thats about the only thing I *knew* about XSLT...But the output doesn't need to be xml, it might be pdf or plain text or ...what ever you want. And all from the same datasource
But how the heck does that happen? The output has to be in the form of a text file? It couldn't write an Window's PE executable...as there is significant pre and post processing that occurs...how would XLST do that? Are there restrictions in output?
I assume processing is somewhat linear? In that you start at the top of the XML document and workd down...but cannot jump back to the begininng to re-process something???
I mean you can change what it looks like. Take the XML in my first post. You could set up XSLT so that each <car> is inside a paragraph with a nice dotted border. Inside that, the tires could be in a table with a green background.Hockey wrote:Soooo...by display...what do you mean???pickle wrote:Basically, XSLT is to XML what CSS on crack would be to XHTML. XSLT can define how XML elements are displayed, but also allows for templates.
I've only used XSLT to transform XML into XHTML - I don't know anything about transforming it to a PDF or anything else.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.