Download code
From LiteratePrograms
Back to Hello_World_(XSL)
Download for Windows: zip
Download for UNIX: zip, tar.gz, tar.bz2
hello-world-lr.xsl
1 <html xsl:version="1.0" 2 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 3 xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <title><xsl:value-of select="doc/title"/></title> 6 </head> 7 <body> 8 <p>Hello <xsl:value-of select="doc/hello"/></p> 9 </body> 10 </html> 11
hello-world-text.xml
1 <exchange> 2 <greeting>What's up, doc?</greeting> 3 <response>Oooooo, you're despicable!</response> 4 </exchange> 5
hello-world-text.xsl
1 <?xml version="1.0" encoding="UTF-8"?> 2 <xsl:stylesheet version="2.0" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 4 5 <xsl:output method="text"/> 6 7 <xsl:template match="/"> 8 <xsl:apply-templates mode="passone"/> 9 <xsl:apply-templates mode="passtwo"/> 10 <xsl:call-template name="recurse"> 11 <xsl:with-param name="num"> 12 <xsl:value-of select="1"/> 13 </xsl:with-param> 14 </xsl:call-template> 15 </xsl:template> 16 17 <xsl:template match="exchange" mode="passone"> 18 <xsl:text>Bugs says: </xsl:text><xsl:value-of select="greeting" /><xsl:text> </xsl:text> 19 </xsl:template> 20 21 <xsl:template match="exchange" mode="passtwo"> 22 <xsl:text>Daffy says: </xsl:text><xsl:value-of select="response" /><xsl:text> </xsl:text> 23 </xsl:template> 24 25 <xsl:template name="recurse"> 26 <xsl:param name="num">1</xsl:param> 27 28 <xsl:if test="not ($num = 11)"> 29 <xsl:text><xsl:value-of select="$num" /> </xsl:text> 30 31 <xsl:call-template name="recurse"> 32 <xsl:with-param name="num"> 33 <xsl:value-of select="$num + 1"/> 34 </xsl:with-param> 35 </xsl:call-template> 36 </xsl:if> 37 </xsl:template> 38 </xsl:stylesheet> 39
hello-world.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3 <html> 4 <head> 5 <title>Hello World Test</title> 6 </head> 7 <body> 8 <p>Hello World</p> 9 </body> 10 </html> 11
hello-world.xml
1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <?xml-stylesheet href="hello-world.xsl" type="text/xsl" ?> 3 <doc> 4 <title>Hello World Test</title> 5 <hello>World</hello> 6 </doc> 7
hello-world.xsl
1 <?xml version="1.0" encoding="iso-8859-1"?> 2 <xsl:stylesheet version="1.0" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 4 xmlns="http://www.w3.org/1999/xhtml"> 5 6 <xsl:output 7 method="xml" 8 encoding="iso-8859-1" 9 indent="yes" 10 doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 11 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 12 /> 13 14 <xsl:template match="/"> 15 16 <html> 17 <head> 18 <title><xsl:value-of select="doc/title"/></title> 19 </head> 20 <body> 21 <p>Hello <xsl:value-of select="doc/hello"/></p> 22 </body> 23 </html> 24 25 </xsl:template> 26 27 </xsl:stylesheet> 28
