This is a continuation of this issue .
I have several <span> tags in a document with several style attributes separated by a semicolon. Right now I have 3 specific style attributes that I am looking for to translate into tags. Everything works well in the example above if the style attribute contains only one of the three style attributes. If span has more, I get an ambiguous match for the rules.
The three style attributes I'm looking for are font-style:italic , font-weight:600 and text-decoration:underline , which should be removed from the style attribute and converted to <em> , <strong> and <u> respectively.
Here is my current XSLT:
<xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="span[ contains(translate(@style, ' ', ''), 'font-style:italic') ]"> <xsl:copy> <xsl:attribute name="style"> <xsl:value-of select="substring-before(@style, ' font-style')"/> <xsl:value-of select="substring-after(@style, 'italic;')"/> </xsl:attribute> <em> <xsl:apply-templates select="node()"/> </em> </xsl:copy> </xsl:template> <xsl:template match="span[ contains(translate(@style, ' ', ''), 'font-weight:600') ]"> <xsl:copy> <xsl:attribute name="style"> <xsl:value-of select="substring-before(@style, ' font-weight')"/> <xsl:value-of select="substring-after(@style, '600;')"/> </xsl:attribute> <strong> <xsl:apply-templates select="node()"/> </strong> </xsl:copy> </xsl:template> <xsl:template match="span[ contains(translate(@style, ' ', ''), 'text-decoration:underline') ]"> <xsl:copy> <xsl:attribute name="style"> <xsl:value-of select="substring-before(@style, ' text-decoration')"/> <xsl:value-of select="substring-after(@style, 'underline;')"/> </xsl:attribute> <u> <xsl:apply-templates select="node()"/> </u> </xsl:copy> </xsl:template>
What will generate an ambiguous rule warning does not work correctly for some elements that contain more than one of the listed attributes.
Input Example:
<span style=" text-decoration: underline; font-weight:600; color:#555555">some text</span>
converted to:
<span style=" font-weight:600; color:#555555"><u>some text</u></span>
when the desired result:
<span style="color:#555555"><b><u>some text</u></b></span>
How can I fix an ambiguous rule match for this?
Thank you in advance
Update:
If I set priorty on each of the templates to descending values ββand run XSLT again on the output of the first XSLT run, everything works as expected. There should be an easier way than running it through the conversion twice. Any ideas?
As suggested by Alejandro and Tomalak, replacing style attributes with a class attribute for CSS classes is also an option.