看看如何利用XSLT来显示"hello world"。
第一步:建立要输入XML文档hello.xml。
<?xml version="1.0" encoding="utf-8"?>
<greeting>Hello, world!</greeting>
这是一个很简单XML文档,只包含一个节点的XML结构树。
第二步:建立XSLT文档hello.xsl。默认的XSLT文件的后缀名为.xsl。
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>First XSLT example</title>
</head>
<body>
<p><xsl:value-of select="greeting"/></p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
第三步:在XML中调用这个XSL文件。修改hello.xml的代码为:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<greeting>Hello, world!</greeting>