How can I apply XSLT on following XML so string between ~ and $ becomes Red in output.
The following XSLT work when you have only one string which contains ~ and $. it will not work when you have more than one string which contains ~ and $. info I am using the same template for DATAC '
I am using Java to compare Strings.
I have a option to change code in java or in XSLT.
Thanks
XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='StyleSheet.xsl'?>
<log >
<rows>
<ID>1</ID>
<DataP>
BookID = UJ2445320A
Qty = 1 ISBN = 45320A
~publishDate = 1/1/2006 $
~Name =Learn XML $
</DataP>
<DataC>
BookID = UJ2445320A
Qty = 1 ISBN = 45320A
~publishDate =2/2/2010$
~Name =Learn XML 1.0 $
</DataC>
</rows>
</log>
XSLT
<xsl:for-each select="rows">
<tr>
<td><xsl:value-of select="ID"/></td>
<xsl:apply-templates select="DataP"/>
<xsl:apply-templates select="DataC"/>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
<xsl:template match="DataP">
<xsl:choose>
<xsl:when test="contains(.,'~')">
<td>
<xsl:value-of select="substring-before(.,'~')"/>
<span style="color:red;"><xsl:value-of select="substring-before(substring-after(.,'~'),'$')"/></span>
<xsl:value-of select="substring-after(.,'$')"/>
</td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="."/></td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
JAVA CODE
StringBuilder sbcp = new StringBuilder();
StringBuilder sbpp = new StringBuilder();
String[] spilt = StringUtils.split(DataC, "|");
String[] spilt2 = StringUtils.split(DataP, "|");
for (int i = 0; i < spilt.length; i++)
{
if(spilt2[i].toString().equals(spilt[i]))
{
sbcp.append(spilt[i]);
sbpp.append(spilt2[i]);
}
else
{
sbcp.append("~").append(spilt[i]).append("$");
sbpp.append("~").append(spilt2[i]).append("$");
}
}