Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old January 5th, 2004, 11:51 AM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sabu21s
Default 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 :)

 
Old January 6th, 2004, 08:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

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

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

Joe, that's much better than the effort I hastily put together to save my embarrasment at posting too quickly. Nice one :D
 
Old January 6th, 2004, 10:30 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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

LOL, I'll use the delete button next time I do that.
 
Old January 6th, 2004, 03:19 PM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sabu21s
Default

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

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)
 
Old January 7th, 2004, 10:50 AM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sabu21s
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
char[...] or string.charAt(...) Ibn_Aziz Java Basics 1 June 14th, 2006 07:08 PM
getting the last CHAR of a string kondapally Crystal Reports 0 December 13th, 2004 03:39 PM
Char in VC and String in VB ??? tranhung Visual C++ 1 February 16th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.