Reputation: 1
First of all, please accept my apologies if I say stupid things in my post! I really don't understand this programming language and have only got so far through trial and error!
I am trying to output a Magento order in to a file, ready for upload to our POS.
Here is my template so far:
<?xml version="1.0"?>
<files>
<file filename="%lastincrementid%.txt">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:output method="text"/>
<xsl:variable name="sepstart" select="'"'"/> <!-- " field start seperator, including '' -->
<xsl:variable name="sepend" select="'",'"/> <!-- field end seperator, including '' -->
<xsl:template match="/">
<xsl:for-each select="orders/order">
<xsl:for-each select="items/item">
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(sku)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(qty)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(price)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(row_total)"/><xsl:value-of select="$sepend" />
<xsl:value-of select="$sepstart" /><xsl:value-of select="normalize-space(../../increment_id)"/><xsl:value-of select="$sepend" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
</file>
</files>
The format of %lastincrementid% is a 9 digit number such as 100007654.
The filename is currently set to be this 9 digit number BUT I want it to be only the last 4 digits, ie 7654.
Can anyone please be kind enough to show me how I go about it? I would be eternally grateful........ :-)
Upvotes: 0
Views: 152
Reputation: 52888
Try using substring()
...
<xsl:value-of select="substring(normalize-space(../../increment_id),6,4)"/>
Edit (complete guess at what is trying to be accomplished)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl">
<xsl:output method="text"/>
<xsl:variable name="sepstart" select="'"'"/>
<!-- " field start seperator, including '' -->
<xsl:variable name="sepend" select="'",'"/>
<!-- field end seperator, including '' -->
<xsl:template match="/">
<xsl:variable name="id">%lastincrementid%</xsl:variable>
<files>
<file filename="{substring($id,6,4)}.txt">
<xsl:for-each select="orders/order">
<xsl:for-each select="items/item">
<xsl:value-of select="$sepstart"/>
<xsl:value-of select="normalize-space(sku)"/>
<xsl:value-of select="$sepend"/>
<xsl:value-of select="$sepstart"/>
<xsl:value-of select="normalize-space(qty)"/>
<xsl:value-of select="$sepend"/>
<xsl:value-of select="$sepstart"/>
<xsl:value-of select="normalize-space(price)"/>
<xsl:value-of select="$sepend"/>
<xsl:value-of select="$sepstart"/>
<xsl:value-of select="normalize-space(row_total)"/>
<xsl:value-of select="$sepend"/>
<xsl:value-of select="$sepstart"/>
<xsl:value-of select="normalize-space(../../increment_id)"/>
<xsl:value-of select="$sepend"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</file>
</files>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1