XSLT
Posted: Mon Aug 28, 2006 6:55 am
- 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?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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
Code: Select all
<car>
<displacement>
3.3L
</displacement>
<tire location="driverfront">
<make>
Bridgestone
</make>
</tire>
<tire location = "driverback">
<make>
Firestone
</make>
</tire>
</car>
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>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`)
);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.
Code: Select all
<html>
<body>
<person name="Alex" age="27">
<person name="Barb" age="23">
</body>
</html>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.
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
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.