Listing 1
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en" >
<head><title>My PHP driven page</title></head>
<?php // load xml data from somewhere
$product = DomNode_first_child($xmldoc);
$productName = DomElement_getAttribute($product, "name");
$productPrice = DomElement_getAttribute($product, "price");
?>
<body>
<p>
Product Name <?php print $productName ?>, price is <?php print $productPrice ?>.
</p>
</body>
</html>
Listing 2
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en"
lang="en">
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<head><title>My JSTL driven page</title></head>
<body>
<p>
Product Name <x:out select="$productXml/name" >{product}</x:out>, price is <x:out select="$productXml/price" />.
</p>
</body>
</html>
Listing 3
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:product="http://.../d/product/1.0"
xml:lang="en" lang="en" >
<head><title>My XSLT driven page</title></head>
<body>
<p>
Product Name <product:name>{product}</ product:name>, price is <product:price />.
</p>
</body>
</html>
Listing 4
<?xml version="1.0" encoding="utf-8"?>
<systems>
<star type="G2">
<name>Sol</name>
<alias>The Sun</alias>
<planet><name>Mercury</name></planet>
<planet><name>Venus</name></planet>
<planet>
<name>Earth</name>
<moon>
<name>The Moon</name>
<alias>Luna</alias>
<alias>Selene</alias>
<alias>Artemis</alias>
<orbit units="km">384400</orbit>
<diameter units="km">3476</diameter>
<mass units="kg">7.35e22</mass>
</moon>
</planet>
<!-- Other planets ommitted for brevity -->
</star>
</systems>
Listing 5
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<!-- Basic template capable of copying entire documents -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Listing 6
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:designer= "http://xml.grumpykitty.biz/designer/stars/1.0"
xmlns:data="http://xml.grumpykitty.biz/stars/1.0">
<!-- Listing 4 content omitted -->
<xsl:template match="designer:copyright">
<xsl:text>(C) 2004 Grumpy Kitty Productions</xsl:text>
</xsl:template>
</xsl:stylesheet>
Listing 7
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="http://xml.grumpykitty.biz/stars/1.0"
>
<!-- A stylesheet parameter is used
to declare the file name -->
<xsl:param name="dataSource" />
<xsl:variable name="dataDoc" select="document($dataSource) " />
<xsl:template match="/">
<xsl:value-of select="count($dataDoc/data:systems/data:star[name='Sol']/planet)" />
</xsl:template>
</xsl:stylesheet>
Listing 8
<xsl:template match="designer:planetGroup">
<xsl:variable name="curNode"
select="current()"/>
<xsl:for-each select="$dataDoc//data:planet">
<xsl:variable name="gId" select="."/>
<xsl:apply-templates select="$curNode"
mode="ignore">
<xsl:with-param name="planetGroup"
select="$gId"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
Listing 9
<!-- Copying entire documents with context -->
<xsl:template match="@*|node()">
<xsl:param name="planetGroup" />
<xsl:copy>
<xsl:apply-templates select="@*|node()">
<xsl:with-param name="planetGroup" select="$planetGroup" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
Listing 10
<!- Iterating over a planets moons. -->
<xsl:template match="designer:moonGroup">
<xsl:param name="starGroup"/>
<xsl:param name="planetGroup"/>
<xsl:variable name="curNode"
select="current()"/>
<xsl:for-each select="$starGroup/data:planet">
<xsl:variable name="gId" select="."/>
<xsl:apply-templates select="$curNode"
mode="ignore">
<xsl:with-param name="starGroup"
select="$starGroup"/>
<xsl:with-param name="planetGroup"
select="$planetGroup"/>
<xsl:with-param name="moonGroup"
select="$gId"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>