|
Subject:
|
Replace or remove the last char from the string
|
|
Posted By:
|
sabu21s
|
Post Date:
|
1/5/2004 10:51:25 AM
|
Hi, I have a string with a ; char at the end of it. I would like to replace it with a space or just delete it. Please help.
Here is my code:
<xsl:if test="TAX"> <TR STYLE="background-color:Yellow"> <TD COLSPAN="9">Taxes : <xsl:if test="TAX/GST"> GST=<xsl:value-of select="TAX/GST"/>;</xsl:if> <xsl:if test="TAX/PST"> PST=<xsl:value-of select="TAX/PST"/>;</xsl:if> <xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/>;</xsl:if> </TD> </TR>
</xsl:if>
Here is my output: Taxes : GST=2.52; HST=5.4; (Would like to remove the last char. Thanks in advance Sabu21s 
|
|
Reply By:
|
pgtips
|
Reply Date:
|
1/6/2004 7:18:10 AM
|
If you don't want the comma, why put it in the stylesheet in the first place? Just change <xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/>;</xsl:if> to <xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/></xsl:if>
|
|
Reply By:
|
pgtips
|
Reply Date:
|
1/6/2004 7:25:15 AM
|
Sorry, replied to that one too quickly - I see your problem now.
<xsl:if test="TAX/GST"> GST=<xsl:value-of select="TAX/GST"/><xsl:if test="TAX/PST or TAX/HST">;</xsl:if></xsl:if>
<xsl:if test="TAX/PST"> PST=<xsl:value-of select="TAX/PST"/><xsl:if test="TAX/HST">;</xsl:if></xsl:if>
<xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/></xsl:if>
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
1/6/2004 9:05:12 AM
|
Something like this may be suitable:
<TAX>
<GST>10</GST>
<HST>20</HST>
<PST>30</PST>
</TAX>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="allTaxes" select="TAX/GST | TAX/HST | TAX/PST"/>
<xsl:for-each select="$allTaxes">
<xsl:value-of select="name()"/>=<xsl:value-of select="."/>
<xsl:if test="position() != last()">;</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Joe (MVP - xml)
|
|
Reply By:
|
pgtips
|
Reply Date:
|
1/6/2004 9:08:47 AM
|
Joe, that's much better than the effort I hastily put together to save my embarrasment at posting too quickly. Nice one
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
1/6/2004 9:30:00 AM
|
Confession time, I posted a reply identical to yours after reading the original post, then I realised what sabu21s meant and I quickly deleted it
--
Joe
|
|
Reply By:
|
pgtips
|
Reply Date:
|
1/6/2004 9:36:10 AM
|
LOL, I'll use the delete button next time I do that.
|
|
Reply By:
|
sabu21s
|
Reply Date:
|
1/6/2004 2:19:59 PM
|
Thanks for your time and help.... I tried Pgtips code first and the first line does not work. I think something with the "OR" syntax. the 2 and 3 line is fine.
Then I tried Joe's code, I just do not get any output of the Select , but just the ; like this "Taxes : " = ;"
Now the fact is, I some times may get only one out of the 3 .... <TAX> <GST>10</GST> </TAX> or sometime get all 3 or get two. Since I am writing the whole out put in one line , I am just separating it with a ;. But I just don't want it at the end. Any help is very much appreciated
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
1/7/2004 6:40:58 AM
|
Show us all the source document, or a small version containing the relevant TAX section and a part of your template where you need the code. The xsl path I showed assumes TAX is a child of document element.
Joe (MVP -xml)
|
|
Reply By:
|
sabu21s
|
Reply Date:
|
1/7/2004 9:50:49 AM
|
Hi Joe, This is the document, - <DETAIL> - <ITEM> <ITEMQTY UOM="CA">120</ITEMQTY> <PRICE UOM="CA">10.45</PRICE> <PRODUCTID TYPE="PI">00001</PRODUCTID> - <MISC> <ITEMDESCR>TEST PRODUCT NUMBER 1</ITEMDESCR> <PACK>24</PACK> <SIZE UOM="LB">1</SIZE> <INNERPACK>5</INNERPACK> </MISC> - <TOTALS> <GROSSAMT>1254</GROSSAMT> <NETAMT>1254</NETAMT> </TOTALS> <IBPRICE UOM="CA">10.45</IBPRICE> - <TAX> <GST>87.78</GST> </TAX> - <ERRORLIST> - <ERROR> <ERRORCODE>108</ERRORCODE> <ERRORSEVERITY>Major</ERRORSEVERITY> <ERRORRESLEVEL>High</ERRORRESLEVEL> <ERRORDESCR>Price .4354 does not match database price of 10.45</ERRORDESCR> </ERROR> </ERRORLIST> </ITEM> </DETAIL> This is the part of the template <xsl:if test="TAX"> <!-- Sabu gave this for the Tax Job -->
<TR STYLE="background-color:Yellow"> <TD COLSPAN="9">Taxes: <xsl:if test="TAX/GST"> GST=<xsl:value-of select="TAX/GST"/> </xsl:if> <xsl:if test="TAX/PST"> PST=<xsl:value-of select="TAX/PST"/> </xsl:if> <xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/> </xsl:if> </TD> </TR>
</xsl:if> <xsl:if test="./ERRORLIST"> <xsl:for-each select="./ERRORLIST/ERROR"> <TR STYLE="background-color:Red"> <TD COLSPAN="9"> <xsl:for-each select ="ERROROVERRIDEID"> <xsl:attribute name ="STYLE">background-color:<xsl:eval>check_string(this)</xsl:eval></xsl:attribute> </xsl:for-each> <FONT COLOR="white"> <B><xsl:choose> <xsl:when match = ".[ERROROVERRIDEID]"> <xsl:for-each select = "ERROROVERRIDEID"><xsl:eval>check_string(this,'ERROR')</xsl:eval> </xsl:for-each> </xsl:when> <xsl:otherwise> Error </xsl:otherwise> </xsl:choose> Description:</B> <xsl:value-of select="ERRORDESCR"/> </FONT> </TD> </TR> </xsl:for-each> </xsl:if> Since it had to be delpoyed I have put it without a ; , Thanks for your help... sabu21s
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
1/8/2004 5:41:12 AM
|
You should be able to replace:
<xsl:if test="TAX">
<!-- Sabu gave this for the Tax Job -->
<TR STYLE="background-color:Yellow">
<TD COLSPAN="9">Taxes:
<xsl:if test="TAX/GST"> GST=<xsl:value-of select="TAX/GST"/> </xsl:if>
<xsl:if test="TAX/PST"> PST=<xsl:value-of select="TAX/PST"/> </xsl:if>
<xsl:if test="TAX/HST"> HST=<xsl:value-of select="TAX/HST"/> </xsl:if>
</TD>
</TR>
</xsl:if>
with:
<xsl:if test="TAX">
<!-- Joe's version -->
<TR STYLE="background-color:Yellow">
<TD COLSPAN="9">Taxes:
<xsl:for-each select="TAX/child::*">
<xsl:value-of select="name()"/>=<xsl:value-of select="."/>
<xsl:if test="position() != last()">;</xsl:if>
</xsl:for-each>
</TD>
</TR>
</xsl:if>
YOU ARE NOT USING XSLT to do this, you are using Microsoft's older and now deprecated draft version as evinced by your use of xsl:eval element. As this is the case I can't guarantee that this will work. Suggest you change xsl namespace to latest version and update stylesheets if possible. See advice at msdn.com/xml or any of the main xml web sites.
Joe (MVP - xml)
|
|
Reply By:
|
pgtips
|
Reply Date:
|
1/8/2004 7:56:45 AM
|
That explains why my simple version didn't work. You have to put $or$ in WD-xsl
|
|
Reply By:
|
sabu21s
|
Reply Date:
|
1/8/2004 4:26:12 PM
|
Anyway.. thanks a lot of all your help. Will take Joes advice and recommend the same to the upper managment.
Thanks Sabu21s
|