Solved

XSL remove comma from output, but losing part of the text

Posted on 2013-05-13
7
420 Views
Last Modified: 2013-06-19
I'm trying to remove any commas that a user inputs, which I've accomplished using a post I found here on Experts Exchange.
<xsl:value-of select="translate(../../shipping/street1,',','')" /><xsl:value-of select="$sepend" />

Open in new window

From what I had previously
<xsl:value-of select="normalize-space(../../shipping/street1)"/><xsl:value-of select="$sepend" />

Open in new window


It's working well, except for one thing.  It is now removing all text prior to the comma!

Thanks in advance for any suggestions!!!

-FDS
0
Comment
Question by:FDMilwaukee
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
This code is not making you loose text before a comma,
something else must do that

The translate function just replaces a ',' with a '', som removes the ','

Can we see the whole XSLT?
0
 
LVL 9

Author Comment

by:FDMilwaukee
Comment Utility
Sure thing, here it is.....
<?xml version="1.0" encoding="UTF-8"?>
<files>
<file filename="customer_data.csv" path="/export" active="true" ftp="false">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:variable name="sepstart"/> <!-- &#34; field start seperator, including '' -->
<xsl:variable name="sepend" select="'&#44;'"/> <!-- field end seperator, including '' -->

<xsl:template match="/">
<xsl:text>"USERNAME","ORDER_NUMBER","ORDER_DATE","SUBTOTAL","SHIPPING","TAX","TOTAL","SHIP","SHIP_ADDRESS_1","SHIP_CITY","SHIP_STATE","SHIP_POSTAL","SHIP_COUNTRY","BILL_NAME","BILL_ADDRESS_1","BILL_CITY","BILL_STATE","BILL_LOCALITY","BILL_POSTAL","BILL_COUNTRY","PHONE_1"</xsl:text><xsl:text>&#xD;</xsl:text>
<xsl:for-each select="orders/order">
<xsl:for-each select="items/item">
<!--<xsl:if test="product_type!='configurable'">-->
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../customer_email)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../increment_id)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="php:functionString('strftime', '%m/%d/%Y', ../../created_at_timestamp)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../subtotal)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../payment/shipping_amount)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../tax_amount)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../total_paid)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="../../shipping/firstname"/><xsl:text> </xsl:text><xsl:value-of select=" ../../shipping/lastname"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="translate(../../shipping/street1,',','')" /><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../shipping/city)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../shipping/region)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../shipping/postcode)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../shipping/country_id)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/firstname)"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(../../billing/lastname)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="translate(../../billing/street1,',','')" /><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/city)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/region)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../BLANK)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/postcode)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/country_id)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../billing/telephone)"/><xsl:value-of select="$sepend" />
	<xsl:text>&#xD;</xsl:text>
<!--</xsl:if>-->
</xsl:for-each>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
</file>
</files> 

Open in new window


It seems odd that I wasn't losing any of the text prior to changing the code to include translate.
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
are there multiple street1 elements at that location?, or maybe multiple text nodes?
not sure it should matter, but using an old libxslt, one never knows

Can you show me the source XML for this?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Author Comment

by:FDMilwaukee
Comment Utility
I'm not sure what you mean by "source xml"
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
An XSLT transforms an XML into antother XML
the source from which you start is the source XML
so the XML that is your start point for this transformation is what I need
0
 
LVL 9

Author Comment

by:FDMilwaukee
Comment Utility
Ok, gotcha that makes sense.  I don't know how I would get that though.  I assumed those values were being pulled directly from the database.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
Comment Utility
oh, but there is a little trick for that

If you replace the XSLT with this one

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>   
</xsl:stylesheet>

Open in new window


you will get the input as the output
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now