Skip to content

Instantly share code, notes, and snippets.

@allen
Forked from anonymous/master.xml
Created November 7, 2012 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allen/4031078 to your computer and use it in GitHub Desktop.
Save allen/4031078 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<data>
<plant-of-the-month>
<section id="20" handle="plant-of-the-month">plant of the month</section>
<entry id="99">
<genus handle="fgfg">fgfg</genus>
<common-name handle="ggfdgb">ggfdgb</common-name>
<latin-name handle="dghgh">dghgh</latin-name>
<flowers-jan>Yes</flowers-jan>
<flowers-feb>Yes</flowers-feb>
<flowers-mar>No</flowers-mar>
</entry>
</plant-of-the-month>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:apply-templates select="data/plant-of-the-month/entry"/>
</xsl:template>
<xsl:template match="data/plant-of-the-month/entry">
<h3>Plant of the Month</h3>
<!-- Iterate over months -->
<xsl:for-each select="*[substring-before(name(), '-') = 'flowers']">
<!-- Pick out the month from the element name -->
<xsl:variable name="month" select="substring-after(name(), '-')"/>
<!-- Lower cases and upper cases used for translation -->
<xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<!-- Pick out the month from the element name and capitalize it -->
<xsl:variable name="cap-month" select="concat(translate(substring($month, 1, 1), $lower, $upper), substring($month, 2))"/>
<a class="btn" href="/plants/{$month}/">
<xsl:if test=". = 'Yes'">
<xsl:attribute name="class">btn btn-success</xsl:attribute>
</xsl:if>
<xsl:value-of select="$cap-month"/>
</a>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment