0

Exporting a csv, need to change the customer postcodes to uppercase.

I've tried searching for the answer and found the following:

XSLT Stylesheet: Changing text to upper case

But this only works for known values or something? My code is as follows:

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

<xsl:template match="/">
<xsl:text>"eBay Username","Name","Postcode","Address","SKU","Samples Wanted","Order id"</xsl:text><xsl:text>&#xA;</xsl:text>

<xsl:for-each select="orders/order">


<xsl:value-of select="$sepstart" /><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="concat(shipping/firstname,shipping/lastname)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="shipping/postcode"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="concat(shipping/street1,', ',shipping/street2,', ',shipping/city)"/><xsl:value-of select="$sepend" />

<xsl:value-of select="$sepstart" />
<xsl:for-each select="items/item">
<xsl:value-of select="sku"/><xsl:text>&#xA;</xsl:text>
</xsl:for-each>
<xsl:value-of select="$sepend" />

<xsl:value-of select="$sepstart" />
<xsl:for-each select="items/item">
<xsl:value-of select="name"/><xsl:text>&#xA;</xsl:text>
</xsl:for-each>
<xsl:value-of select="$sepend" />


<xsl:value-of select="increment_id"/>


<xsl:text>&#xA;</xsl:text>


</xsl:for-each>
</xsl:template>

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

Postcodes are here:

<xsl:value-of select="shipping/postcode"/>

Is this possible? You can't quickly change to uppercase in excel either, this is a daily export (and I need anyone to be able to do it!)

Community
  • 1
  • 1
  • Not sure what you mean by "this only works for known values". There are no case-changing functions in XSLT 1.0, so you need to enumerate the characters you want to be affected. That is the problem with the solution you linked to: it won't work with diacritics, for example. – michael.hor257k Aug 11 '14 at 15:32
  • I clearly haven't a clue with this. It's only UK postcodes, so it's standard abc's. Also I've tried the solution above but I don't know how to get it to work. – richabradshaw Aug 12 '14 at 08:44

1 Answers1

0

Also I've tried the solution above but I don't know how to get it to work.

Step 1:

Place these two variables at the top of your stylesheet, outside of any template:

<xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

Step 2:

Replace this part:

<xsl:value-of select="shipping/postcode"/>

with:

<xsl:value-of select="translate(shipping/postcode, $lowercase, $uppercase)"/>

Step 3:

Report your progress here.

--
Unrelated to your question, but it looks like your stylesheet could do with some streamlining to avoid the repetitive parts - perhaps by calling a named template to create the "field"?

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51