 |
XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

September 20th, 2006, 08:22 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Format a string of alphanumeric characteres
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="Order"><xsl:text/>
<xsl:variable name="ref" select="normalize-space(./OrderReferences)"/>
<xsl:variable name="ref1" select="normalize-space(./Sender/SenderReferences/GLN)"/>
<xsl:text/>
<xsl:variable name="ref2" select="('0000000000')"/>
<xsl:for-each select="./OrderLine">
<xsl:value-of select="$ref"/>
<xsl:value-of select="$ref1"/>
<xsl:value-of select="$ref2"/>
<xsl:value-of select="format-number(normalize-space(LineNumber),'000000')"/>
<xsl:value-of select="concat('00000000000',normalize-space(Product/TradeUnitCode))"/><xsl:text/>
<xsl:value-of select="format-number(normalize-space(substring-before(Quantity,'.')), '000000000000')"/><xsl:text/>
<xsl:value-of select="('000000000000')"/>#013;<xsl:text/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
my output file is:
N10072242009PT500333041415056300000000000026400000 00000007316224000000001200000000000000
N10072242009PT500333041415056300000000000026500000 00000007345132000000000300000000000000
What i would like is to format this <xsl:variable name="ref" select="normalize-space(./OrderReferences)"/> to have 20 characteres but i can´t use the format-number instruction because it have alphanumeric characteres and then i get NaN.
Can someone help me please.
|

September 20th, 2006, 09:12 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
To pad an arbitrary string $s with leading "0" characters to a length of 20 characters, try
substring(concat('00000000000000000000', $s), string-length($s)+1)
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

September 20th, 2006, 09:30 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mhkay but where i put normalize-space(./OrderReferences) in you instruction:
substring(concat('00000000000000000000', $s), string-length($s)+1)
Please put my instruction in yours, please.
Thank you.
|

September 20th, 2006, 09:46 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I gave you an expression that you can apply to any input string, which I called $s. If you want to apply it to the result of normalize-space(./OrderReferences) then you can either replace $s by that expression, or you can assign the result of that expression to a variable and use the variable.
This seems rather basic.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

September 21st, 2006, 04:48 AM
|
Registered User
|
|
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<!ELEMENT train (engine?, wagon*)>
<!ELEMENT engine(#PCDATA)>
<!ELEMENT wagon(#PCDATA)>
murugesan
|

September 21st, 2006, 05:01 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Well this wins the award of the month for the most cryptic post :)
--
Joe ( Microsoft MVP - XML)
|

September 21st, 2006, 05:37 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you mhkay it work just fine.
You are the best.
joefawcett are you joking about my post????!!!
|

September 21st, 2006, 06:03 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Quote:
quote:Originally posted by hugoscp
joefawcett are you joking about my post????!!!
|
No, I should have quoted the one I was talking about, the one from murgesh :)
--
Joe ( Microsoft MVP - XML)
|

September 21st, 2006, 06:07 AM
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No problem, i was only joking with you.
|
|
 |