How to apply or chain multiple matching templates in XSLT?

Posted by Ignatius on Stack Overflow See other posts from Stack Overflow or by Ignatius
Published on 2010-05-07T20:11:39Z Indexed on 2010/05/07 20:18 UTC
Read the original article Hit count: 297

Filed under:
|

I am working on a stylesheet employing many templates with match attributes:

<xsl:template match="//one" priority="0.7">
   <xsl:param name="input" select="."/>
   <xsl:value-of select="util:uppercase($input)"/>
   <xsl:next-match />
</xsl:template>

<xsl:template match="/stuff/one">
    <xsl:param name="input" select="."/>
    <xsl:value-of select="util:add-period($input)"/>
</xsl:template>

<xsl:function name="util:uppercase">
    <xsl:param name="input"/>
    <xsl:value-of select="upper-case($input)"/>
</xsl:function>

<xsl:function name="util:add-period">
    <xsl:param name="input"/>
    <xsl:value-of select="concat($input,'.')"/>
</xsl:function>

What I would like to do is be able to 'chain' the two functions above, so that an input of 'string' would be rendered in the output as 'STRING.' (with the period.) I would like to do this in such a way that doesn't require knowledge of other templates in any other template. So, for instance, I would like to be able to add a "util:add-colon" method without having to open up the hood and monkey with the existing templates.

I was playing around with the <xsl:next-match/> instruction to accomplish this. Adding it to the first template above does of course invoke both util:uppercase and util:add-period, but the output is an aggregation of each template output (i.e. 'STRINGstring.') It seems like there should be an elegant way to chain any number of templates together using something like <xsl:next-match/>, but have the output of each template feed the input of the next one in the chain. Am I overlooking something obvious?

© Stack Overflow or respective owner

Related posts about xslt

Related posts about Xml