XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Cynthia van BovenSubject: Xquery string-pad function
Author: Cynthia van Boven
Date: 26 Jan 2009 03:57 AM
Good morning all,

I'd like to concat two strings in an xml tag and fill out the first string with spaces up to ten positions. I think it can be done by means of a string-pad function, but how do I use it. I have added the namespace where this function is found, but it is not recognized. Here is my code:

for $Absences in collection("Synergist.dbo.Absences")/Absences
where ($Absences/Type = 205) and concat(string(year-from-dateTime($Absences/Approved)),("-"),string(month-from-dateTime($Absences/Approved)),("-"),string(day-from-dateTime($Absences/Approved)))=concat(year-from-dateTime(current-dateTime()),("-"),month-from-dateTime(current-dateTime()),("-"),day-from-dateTime(current-dateTime()))
return
<AVXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn="http://www.w3.org/2003/05/xpath-functions">
<SONRQ>
<DTCLIENT>2006-09-21T10:51:11</DTCLIENT>
<USERID>DEMO</USERID>
<USERPASS>demo</USERPASS>
<ADMIN>NL_YR_GRD</ADMIN>
<APPID>ACCVW</APPID>
<APPVER>0701A</APPVER>
</SONRQ>
<EBUSMSGSRQ>
<EBUSTRNRQ>
<TRNUID>A1WI0N90OJ</TRNUID>
<BUSOBJ>OI5</BUSOBJ>
<ROWMODRQ>
{for $Creditor in collection("Synergist.dbo.cicmpy")/cicmpy[cmp_wwn=$Absences/CustomerID]
return
<RECID>{concat(string(normalize-space($Creditor/cmp_code)),fn:string-pad("",4))}</RECID>
}
<OI_STAT>4</OI_STAT>
<DISP_INV>.F.</DISP_INV>
</ROWMODRQ>
</EBUSTRNRQ>
</EBUSMSGSRQ>
</AVXML>

Postnext
Ivan PedruzziSubject: Xquery string-pad function
Author: Ivan Pedruzzi
Date: 26 Jan 2009 11:53 AM
See the following example

declare function local:string-pad($source as xs:string, $padCount as xs:integer, $padString as xs:string)
{
let $pad := $padCount - string-length($source)
return concat($source, string-join((for $i in 1 to $pad return $padString), ''))
};

string-join(
("'", local:string-pad("1" , 3, " "),"'&#10;",
"'", local:string-pad("12" , 3, " "),"'&#10;",
"'", local:string-pad("123", 3, " "),"'&#10;"), '')

Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
Cynthia van BovenSubject: Xquery string-pad function
Author: Cynthia van Boven
Date: 26 Jan 2009 02:49 PM
Hi Ivan,

I see how this function can work, still a problem is where to place the code in my xquery. I would expect this part on the top of my file

declare function local:string-pad($source as xs:string, $padCount as xs:integer, $padString as xs:string)
{
let $pad := $padCount - string-length($source)
return concat($source, string-join((for $i in 1 to $pad return $padString), ''))
};

and then in the recid tag the function itself: local:string-pad("1" , 3, " ")

but now I get a blank file.

Can you give me another clue?

Thanks!


Cynthia

Postnext
Ivan PedruzziSubject: Xquery string-pad function
Author: Ivan Pedruzzi
Date: 26 Jan 2009 03:00 PM

Email your xquery and some sample XML data to

stylus-field-report @ progress.com

we will take a look.

Ivan Pedruzzi
Stylus Studio Team

Posttop
Cynthia van BovenSubject: Xquery string-pad function
Author: Cynthia van Boven
Date: 26 Jan 2009 04:48 PM
Hi Ivan,

Hope you haven't spent time yet on the mail I posted you, cause I now discovered why it was not working: my where clause worked yesterday, but no records are within scope today! Aaargh, looking for a mistake in the wrong section.

Thank you so much, it now works!

Cynthia

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.