Created
May 22, 2010 17:31
-
-
Save nils-werner/410225 to your computer and use it in GitHub Desktop.
XSLT Loop
This file contains hidden or 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" | |
exclude-result-prefixes="xsl"> | |
<xsl:template name="loop"> <!-- Loop --> | |
<xsl:param name="i" /> | |
<xsl:param name="limit" /> | |
<xsl:call-template name="loop-item"> | |
<xsl:with-param name="i" select="$i"/> | |
<xsl:with-param name="limit" select="$limit"/> | |
</xsl:call-template> | |
<xsl:choose> | |
<xsl:when test="$i < $limit"> | |
<xsl:call-template name="loop"> | |
<xsl:with-param name="i" select="$i + 1" /> | |
<xsl:with-param name="limit" select="$limit" /> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:when test="$i > $limit"> | |
<xsl:call-template name="loop"> | |
<xsl:with-param name="i" select="$i - 1" /> | |
<xsl:with-param name="limit" select="$limit" /> | |
</xsl:call-template> | |
</xsl:when> | |
</xsl:choose> | |
</xsl:template> | |
<xsl:template name="loop-item"> <!-- Empty Loop Item, has to be overloaded --> | |
<xsl:param name="i" /> | |
<xsl:param name="limit" /> | |
</xsl:template> | |
</xsl:stylesheet> |
This file contains hidden or 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
<xsl:template match="data"> | |
<xsl:apply-templates select="your-ds" /> | |
</xsl:template> | |
<xsl:template match="your-ds"> | |
<h2><xsl:value-of select="section" /></h2> | |
<xsl:call-template name="years" /> | |
</xsl:template> |
This file contains hidden or 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" | |
exclude-result-prefixes="xsl"> | |
<xsl:import href="../utilities/loop.xsl"/> | |
<xsl:template name="years"> <!-- Years-wrapper for Loop --> | |
<xsl:param name="from" select="$this-year" /> | |
<xsl:param name="to" select="'1990'" /> | |
<xsl:call-template name="loop"> | |
<xsl:with-param name="i" select="$from" /> | |
<xsl:with-param name="limit" select="$to" /> | |
</xsl:call-template> | |
</xsl:template> | |
<xsl:template name="years-item"> <!-- Years-Item, called by loop item --> | |
<xsl:param name="i" /> | |
<xsl:param name="limit" /> | |
<xsl:if test="entry[substring(datum, 1, 4) = $i]"> | |
<h3><xsl:value-of select="$i" /></h3> | |
<ul> | |
<xsl:apply-templates select="entry[substring(datum, 1, 4) = $i]"/> | |
</ul> | |
</xsl:if> | |
</xsl:template> | |
<xsl:template name="loop-item"> <!-- Overload for Loop Item --> | |
<xsl:param name="i" /> | |
<xsl:param name="limit" /> | |
<xsl:call-template name="years-item"> | |
<xsl:with-param name="i" select="$i" /> | |
<xsl:with-param name="limit" select="$limit" /> | |
</xsl:call-template> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment