i wrote a xslt code which converts a xml file to a html file which contains lot of tables, one of the column contains messages(very long messages), but that line starts with either of the two words "Verification Passed" or "Verification failed"
My requirement is to make the entire table row red if verification failed and make entire table row green if verification passed
<xsl:choose>
<xsl:when test="contains(@message,'Verification failed:')"><td bgcolor="#FF0000"> <xsl:value-of select="@Message"/></td></xsl:when>
<xsl:when test="contains(@message,'Verification passed:')"><td bgcolor="#00FF00"><xsl:value-of select="@Message"/></td></xsl:when>
<xsl:otherwise><td> <xsl:value-of select="@Message"/></td></xsl:otherwise>
</xsl:choose>
Unfortunately you don't say what you expect your "trim()" function to do. But from your description of the requirement, I would guess that normalize-space() is close enough:
The XPath normalize-space() function differs from the Java trim() method in that (a) it replaces internal sequences of whitespace characters by a single space, and (b) it has a slightly different definition of whitespace.
using XSLT1 with registerLangFunctions
Today, ~10 years after (complex) XSLT2 standard released, many projects yet use (faster) XSLT1. Perhaps the problem is not only "simple vs complex", but XSLT1 is a fact for Perl, PHP, Python, PostgreSQL, and many other communities.
So, a solution for Perl, PHP and Python: use your main language to do
trim
and another usual functions that not exists into XSLT1.Here an example of PHP: https://en.wikibooks.org/wiki/PHP_Programming/XSL/registerPHPFunctions
I. XSLT 1.0
No, and it is rather difficult to perform "trim" in XSLT 1.0.
Here is the
trim
function/template from FXSL:When this transformation is performed (you have to download at least a few other stylesheet modules, which comprise the complete import tree) on this XML document:
the wanted, correct result is produced:
II In XSLT 2.0 / XPath 2.0
Still a little bit tricky, but very short:
Here is the complete, corresponding transformation:
and when applied on the same XML document (above), the same correct result is produced: