I've come across the following snippet in an XSL
file that I'm working with. The XSL
is basically converting HTML
tags and international content (characters with accents mostly) into a format digestable by QuarkXPress.
I'm not familiar with XSL at all and judging by the code it looks like we're checking some content against a regular expression, converting it if it matches, and if not we're passing it along to see if the next template can match it.
The approach seems OK to my untrained eyes but the XSL file is full of duplication.
There must be a cleaner way of writing this. Can you help me out?
Edit: Explaining duplication.
In the block below, I've got two blocks that are nearly identical, there are about 50 more of these blocks in the file. The only things that change between blocks are: the template name, the regex, the content of the matching-substring tag and what is called in the non-matching-substring block.
<!-- convert HTML <br> tag to ASCII/Quark new line tag -->
<xsl:template name="break-tag">
<xsl:param name="string" select="string(.)"/>
<xsl:analyze-string select="$string" regex="<br>" flags="i">
<xsl:matching-substring>
<xsl:text disable-output-escaping="yes"><\n></xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:call-template name="open-list-tag"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<!-- convert HTML <li> tag to Bull Text stylesheet with bullet tag and tab tag -->
<xsl:template name="open-list-tag">
<xsl:param name="string" select="string(.)"/>
<xsl:analyze-string select="$string" regex="<li>" flags="i">
<xsl:matching-substring>
<xsl:text disable-output-escaping="yes">@F07/2 Bullet Points:</xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:call-template name="euro-char-entity"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>