Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-05-13
7
Medium Priority
?
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn how to dynamically set the form action using jQuery.
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.

704 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