Skip to content

Instantly share code, notes, and snippets.

@ctipper
Created September 28, 2012 17:10
Show Gist options
  • Save ctipper/3801033 to your computer and use it in GitHub Desktop.
Save ctipper/3801033 to your computer and use it in GitHub Desktop.
Create Docbook keywordset from comma-delimited list of keywords. Of general applicability.
<!-- process keywords -->
<xsl:template match="keywords">
<xsl:element name="keywordset">
<xsl:call-template name="keyword">
<xsl:with-param name="keyword-names"><xsl:value-of select="."/>
</xsl:with-param>
</xsl:call-template>
</xsl:element>
</xsl:template>
<xsl:template name="keyword">
<xsl:param name="keyword-names">keywords here, more keywords</xsl:param>
<xsl:choose>
<xsl:when test="contains($keyword-names,',')">
<xsl:element name="keyword">
<xsl:choose>
<xsl:when test="substring($keyword-names,1,1)=' '">
<xsl:value-of select="substring-before(
substring-after($keyword-names,' '),
',')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($keyword-names,',')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<xsl:call-template name="keyword">
<xsl:with-param name="keyword-names">
<xsl:value-of select="substring-after($keyword-names,',')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:element name="keyword">
<xsl:choose>
<xsl:when test="substring($keyword-names,1,1)=' '">
<xsl:value-of select="substring-after($keyword-names,' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$keyword-names"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment