SLIDE 2 2
5
An Introduction to XML and Web Technologies
Using XSLT Using XSLT
<?xml-styleshe <?xml-stylesheet et type="text/ type="text/xsl" href="bus xsl" href="businesscard.xsl" inesscard.xsl"?> ?> <card xmlns="http://businesscard.org"> <name>John Doe</name> <title>CEO, Widget Inc.</title> <email>john.doe@widget.inc</email> <phone>(202) 555-1414</phone> <logo uri="widget.gif"/> </card>
6
An Introduction to XML and Web Technologies
XSLT for Business Cards (1/2) XSLT for Business Cards (1/2)
<xs <xsl: l:sty style lesh sheet eet ve vers rsion ion=" ="2. 2.0" 0" xml xmlns ns:x :xsl= sl="ht "http tp:// ://ww www. w.w3. w3.org
/1999 999/X /XSL SL/Tr /Trans ansfo form" rm" xml xmlns ns:b :b="h ="http ttp:/ ://bu /busi sine nessc sscard ard.o .org" rg" xml xmlns ns=" ="htt http:/ p://w /www. ww.w3 w3.o .org/ rg/199 1999/ 9/xht xhtml ml"> "> <xsl:t <xsl:tem empl plate ate ma matc tch=" h="b: b:ca card" rd"> <html> <head> <title><xs <xsl: l:val value ue-o
f sele elect ct="b ="b:n :nam ame/t e/text ext() ()"/> "/></title> </head> <body bgcolor="#ffffff"> <table border="3"> <tr> <td> <xsl xsl:a :appl pply- y-te templ mplate ates sel s selec ect= t="b: "b:nam name" e"/> /><br/> <xsl xsl:a :appl pply- y-te templ mplate ates sel s selec ect= t="b: "b:tit title le"/> "/><p/> <tt><xsl: <xsl:ap appl ply-t y-temp empla lates tes s select ect="b ="b:e :emai mail" l"/> /></ </tt><br/>
7
An Introduction to XML and Web Technologies
XSLT for Business Cards (2/2) XSLT for Business Cards (2/2)
<xsl xsl:i :if t f test="b: "b:pho phone ne"> "> Phone: <xsl <xsl:ap :apply ply-t
empla late tes s s sele elect ct="b ="b:p :pho hone" ne"/> /><br/> </xs /xsl: l:if> if> </td> <td> <xsl xsl:i :if t f test="b: "b:log logo"
<img src="{b:logo {b:logo/@ /@uri uri}"/> </xs /xsl: l:if> if> </td> </tr> </table> </body> </html> </xsl: </xsl:te temp mplat late> e> <xsl:t <xsl:tem empl plate ate ma matc tch=" h="b: b:na name| me|b:t b:tit itle| le|b: b:em email ail|b: |b:ph phone
"> <xsl xsl:v :val alue- ue-of se
lect= t="t "text ext()" ()"/> /> </xsl: sl:te temp mplat late> e> </x </xsl sl:st :styl yles eshee heet> t>
8
An Introduction to XML and Web Technologies
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> ... </xsl:stylesheet>
An XSLT stylesheet contains template rules The processor finds the most specific rule for the document root It then executes the template body
XSLT Stylesheets XSLT Stylesheets