Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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
 
Old September 20th, 2006, 08:22 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old September 20th, 2006, 09:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old September 20th, 2006, 09:30 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.


 
Old September 20th, 2006, 09:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old September 21st, 2006, 04:48 AM
Registered User
 
Join Date: Sep 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to murgesh
Default

<!ELEMENT train (engine?, wagon*)>
<!ELEMENT engine(#PCDATA)>
<!ELEMENT wagon(#PCDATA)>


murugesan
 
Old September 21st, 2006, 05:01 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well this wins the award of the month for the most cryptic post :)

--

Joe (Microsoft MVP - XML)
 
Old September 21st, 2006, 05:37 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you mhkay it work just fine.
You are the best.

joefawcett are you joking about my post????!!!

 
Old September 21st, 2006, 06:03 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old September 21st, 2006, 06:07 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem, i was only joking with you.






Similar Threads
Thread Thread Starter Forum Replies Last Post
count the string from csv format sudhirbharti C# 1 March 25th, 2008 03:16 PM
format-number on a string? dep XSLT 1 October 31st, 2006 01:24 PM
String format gugu C# 1 April 20th, 2006 03:08 PM
input string was not in a correct format kunal.net VS.NET 2002/2003 1 October 11th, 2005 12:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.