 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 5th, 2004, 11:51 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Replace or remove the last char from the string
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 :)
|
|

January 6th, 2004, 08:18 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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>
|
|

January 6th, 2004, 08:25 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sorry, replied to that one too quickly - I see your problem now.
Code:
<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>
|
|

January 6th, 2004, 10:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Something like this may be suitable:
Code:
<TAX>
<GST>10</GST>
<HST>20</HST>
<PST>30</PST>
</TAX>
Code:
<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)
|
|

January 6th, 2004, 10:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Joe, that's much better than the effort I hastily put together to save my embarrasment at posting too quickly. Nice one :D
|
|

January 6th, 2004, 10:30 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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
|
|

January 6th, 2004, 10:36 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
|
|
LOL, I'll use the delete button next time I do that.
|
|

January 6th, 2004, 03:19 PM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 7th, 2004, 07:40 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

January 7th, 2004, 10:50 AM
|
|
Registered User
|
|
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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">
<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>
<B><xsl:choose>
<xsl:when match = ".[ERROROVERRIDEID]">
<xsl:for-each select = "ERROROVERRIDEID"><xsl:eval>check_string(this,'ERR OR')</xsl:eval>
</xsl:for-each>
</xsl:when>
<xsl:otherwise> Error </xsl:otherwise>
</xsl:choose> Description:</B>
<xsl:value-of select="ERRORDESCR"/>
</TD>
</TR>
</xsl:for-each>
</xsl:if>
Since it had to be delpoyed I have put it without a ; ,
Thanks for your help...
sabu21s
|
|
 |