Skip to content

Instantly share code, notes, and snippets.

@kellylougheed
Created December 5, 2016 02:24
Show Gist options
  • Save kellylougheed/05bafa3b58d4efcdea5c35a300ac6b92 to your computer and use it in GitHub Desktop.
Save kellylougheed/05bafa3b58d4efcdea5c35a300ac6b92 to your computer and use it in GitHub Desktop.
Colors every other word in a string by tokenizing the string and wrapping every other word in <span> tags.
<xsl:template match="your-html-element">
<div class="color-every-other">
<xsl:variable name="content" select="path-to-content"/>
<xsl:for-each select="tokenize($content, ' ')">
<xsl:choose>
<xsl:when test="position() mod 2 != 0">
<span><xsl:value-of select="concat(., ' ')"/></span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(., ' ')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment