Created
December 6, 2011 22:18
-
-
Save greystate/1440293 to your computer and use it in GitHub Desktop.
Basic client-side XML/XSLT setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-stylesheet type="text/xml" href="transform.xslt"?> | |
<data> | |
<page id="contact"> | |
<p> | |
Our contact info: | |
</p> | |
<name>Moe Zart</name> | |
<email>moe@moesbar.com</email> | |
</page> | |
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<?xml-stylesheet type="text/xml" href="transform.xslt"?> | |
<data> | |
<page id="front"> | |
<header>The Front Page</header> | |
<p> | |
You can contact us from the <link>contact</link> page. | |
</p> | |
</page> | |
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
> | |
<!-- Note: about:legacy-compat is the XSLT version of the HTML5 DOCTYPE --> | |
<xsl:output method="html" indent="yes" | |
omit-xml-declaration="yes" | |
doctype-public="about:legacy-compat" | |
/> | |
<xsl:template match="/"> | |
<html> | |
<head> | |
<title>Demo</title> | |
</head> | |
<body> | |
<xsl:apply-templates select="data/page" /> | |
</body> | |
</html> | |
</xsl:template> | |
<xsl:template match="page"> | |
<article> | |
<xsl:apply-templates /> | |
</article> | |
</xsl:template> | |
<xsl:template match="header"> | |
<h1> | |
<xsl:apply-templates /> | |
</h1> | |
</xsl:template> | |
<xsl:template match="p"> | |
<xsl:copy> | |
<xsl:apply-templates /> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="link"> | |
<a href="{.}.xml"> | |
<xsl:apply-templates /> | |
</a> | |
</xsl:template> | |
<xsl:template match="email"> | |
<div class="email"> | |
<a href="mailto:{.}"><xsl:value-of select="." /></a> | |
</div> | |
</xsl:template> | |
<xsl:template match="name"> | |
<div class="name"> | |
<xsl:value-of select="." /> | |
</div> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment