Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-13
7
Medium Priority
?
439 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
ID: 39161663
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
ID: 39161685
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
ID: 39162200
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 9

Author Comment

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

Expert Comment

by:Geert Bormans
ID: 39162225
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
ID: 39162259
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 2000 total points
ID: 39162434
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Simple Linear Regression

879 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