Solved

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

Posted on 2013-05-13
7
427 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

733 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