GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Apr-2003, 06:37
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,060
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough

[Tutorial] XSL Basics Pt. I


XSL

So you what to learn XSL. Well set back and relax because I’m going to teach you how.
First there are a few things that you may what to know and remember XSL is a W3C Standard
But that doesn’t mean that everyone is ready for it. The first two parts of the language (XSLT
And XPath ) became a W3C recommendation in Nov 99. The full XSL recommendation including
XSL formatting became a W3C recommendation in Oct 01. So you may ask what all this means
Well it means that some web browsers will not work or will have problems displaying all option available in XSL. So I would
Recommend that if your able to use IE 6 or Netscape 6 do IE 5 or 5.5 will not work with all of this
Articale. Ok lets learn a little about XSL shall we?

XSL consists of three parts:

XSLT (a language for transforming XML documents)
Xpath (a language for defining parts of an XML document)
XSL Formatting Objects (a vocabulary for formatting XML documents)

If this is all confusing you think of it this way. XSL is a language that can transform XML into XHTML,
A language that can filter and sort XML data, a language that can define parts of an XML document
A language that can format XML data based on the data value. A language that can output XML data
To different devices, like screen, paper or voice all of this from XSL. Ok so lets get are hands dirty.

The root element that declares the document to be XSL style sheet is
<xsl:stylesheet> and <xsl:transform>, you can use either.

The correct way to declare an XSL style sheet according to the W3C XSL Recommendation is
HTML Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
or
HTML Code:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Note: The xmlns:xsl="http://www.w3.org/1999/XSL/Transform" identifies
the official W3C XSL recommendation namespace. If you use the namespace, you must include the version="1.0". If your using IE 6 or Netscape 6 you should use one of the codes above.

Lets take a look at how to transform an XML document (gamelist.xml) into XHTML:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <gamelist> <game> <title>Homeworld</title> <developer>Relic</developer> <publisher>Sierra</publisher> <genre>Strategy</genre> <price>49.95</price> <year>1999</year> </game> </gamelist>

First you create an XSL Style Sheet (gamelist.xsl) with a transformation template:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <body> <h2>Game List</h2> <table border="1"> <tr bgcolor="#6666FF"> <th align="left">Title</th> <th align="left">Developer</th> <th align="left">Publisher</th> </tr> <xsl:for-each select="gamelist/game"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="developer"/></td> <td><xsl:value-of select="publisher"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>

Finally, Return to your first XML document (gamelist.xml) and add an XSL Style Sheet reference to your XML document like so:
HTML Code:
<?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="gamelist.xsl"?> <gamelist> <game> <title>Homeworld</title> <developer>Relic</developer> <publisher>Sierra</publisher> <genre>Strategy</genre> <price>49.95</price> <year>1999</year> </game> </gamelist>

That’s it your done, You have just learned how to transform XML into XHTML using XSL.
Well that’s it for my first article. Next time we will break down the example here and discuss XSL in greater detail including XSL template, value-of and for-each.

[gid=http://www.desilva.biz/forum/viewtopic573.php]XSL Basics Pt. II[/gid]
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
Last edited by pcxgamer : 17-Apr-2003 at 07:20.
  #2  
Old 17-Apr-2003, 07:14
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
What is the href value here?
HTML Code:
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
  #3  
Old 17-Apr-2003, 07:16
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,060
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough
A mistake sorry I'll edit that it should be:
HTML Code:
<?xml-stylesheet type="text/xsl" href="gamelist.xsl"?>
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #4  
Old 17-Apr-2003, 07:33
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Is there anywhere I can see where this is used? It looks quite interesting.
  #5  
Old 17-Apr-2003, 07:44
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,060
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough
Here you go you can check out the source but if you would like the file I'll send then to you

XML
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #6  
Old 17-Apr-2003, 07:46
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
How come it doesn't show the price and year their?
  #7  
Old 17-Apr-2003, 07:48
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,060
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough
I'm checking on that right now. I didn't really set that up for display. But I'm check right now I'll have it fix shortly.
Sorry
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #8  
Old 17-Apr-2003, 07:50
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
No need to apologise, I wasn't meaning that I was just trying to work out what was going on and making sure it wasn't at my end
  #9  
Old 17-Apr-2003, 07:59
pcxgamer's Avatar
pcxgamer pcxgamer is offline
Senior Member
 
Join Date: Sep 2002
Location: South Carolina, USA
Posts: 1,060
pcxgamer is a jewel in the roughpcxgamer is a jewel in the roughpcxgamer is a jewel in the rough
Are you use IE 6 or netscape 6?
__________________
If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.
  #10  
Old 17-Apr-2003, 08:05
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
IE6, I tried it in Mozilla but like you said, it didn't like it. I'm surprised since Mozilla is supposed to be quite forward in new things like that.
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] XSL Basics Pt. III pcxgamer Web Design Forum 1 24-Apr-2003 08:04
[Tutorial] XSL Basics Pt. II pcxgamer Web Design Forum 0 21-Apr-2003 07:11
[Tutorial] MySQL Basics nniehoff MySQL / PHP Forum 15 23-Mar-2003 19:42

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:40.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.