Created
May 10, 2012 14:41
-
-
Save xpathr/2653551 to your computer and use it in GitHub Desktop.
Pluralize by phoque
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"> | |
| <!-- | |
| Param "number" is required, all other params are optional. | |
| If you don't give a "term" param, the util assumes that you mean 'Element'. | |
| If you don't give a "term-plural" param, the util assumes that it will only have to append an 's' | |
| If you don't give a "term-none" param, the util assumes that it will be the same as term-plural | |
| If you don't five a "term-neg" param, the util assumes that negative elements term is the same as term-plural | |
| --> | |
| <xsl:template name="pluralize"> | |
| <xsl:param name="number" /> | |
| <xsl:param name="term" select="'Element'" /> | |
| <xsl:param name="term-plural" select="concat($term,'s')" /> | |
| <xsl:param name="term-none" select="$term-plural" /> | |
| <xsl:param name="term-neg" select="$term-plural" /> | |
| <xsl:if test="$number < 0"> | |
| <xsl:value-of select="$term-neg" /> | |
| </xsl:if> | |
| <xsl:if test="$number = 0"> | |
| <xsl:value-of select="$term-none" /> | |
| </xsl:if> | |
| <xsl:if test="$number = 1"> | |
| <xsl:value-of select="$term" /> | |
| </xsl:if> | |
| <xsl:if test="$number > 1"> | |
| <xsl:value-of select="$term-plural" /> | |
| </xsl:if> | |
| </xsl:template> | |
| </xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment