Skip to content

Instantly share code, notes, and snippets.

@ethangardner
Created September 21, 2011 17:35
Show Gist options
  • Save ethangardner/1232751 to your computer and use it in GitHub Desktop.
Save ethangardner/1232751 to your computer and use it in GitHub Desktop.
Using templates instead of foreach in XSL
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<h3 id="keynotes">Keynotes</h3>
<ul class="none" id="speakers">
<xsl:apply-templates />
</ul>
</xsl:template>
<xsl:template match="item">
<li>
<xsl:apply-templates select="SpeakerPhoto1"/>
<div class="sessionDetails">
<xsl:apply-templates select="SessionURL" />
<xsl:apply-templates select="Title" />
<xsl:apply-templates select="SessionName" />
<xsl:apply-templates select="SessionDescription" />
</div>
<div class="clear"></div>
</li>
</xsl:template>
<xsl:template match="SpeakerPhoto1">
<div class="speakerPhoto">
<xsl:value-of select="." disable-output-escaping="yes" />
</div>
</xsl:template>
<xsl:template match="SessionURL">
<span class="hide sessionURL">
<xsl:value-of select="." disable-output-escaping="yes" />
</span>
</xsl:template>
<xsl:template match="Title">
<h3><xsl:value-of select="." /></h3>
</xsl:template>
<xsl:template match="SessionName">
<p><em><xsl:value-of select="." /></em></p>
</xsl:template>
<xsl:template match="SessionDescription">
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment