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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
+ XSLT Help and Discussion (7625)
- XQuery Help and Discussion (2017)
-> + how to list distinct value? (5)
-> + Reading XML Files Across Netwo... (8)
-> + I want to automatically check ... (4)
-> + Parent tags (5)
-> + Remove Empty tags (2)
-> + dynamic function call | dynami... (3)
-> + Can I define a function like f... (3)
-> + remove empty tags (4)
-> + Loops (7)
-> + flat to XML with xQuery (4)
-> + Xquery for timer based events. (2)
-> + Cleaning up Word 2007 xml (3)
-> - Xquery string-pad function (5)
-> ->Xquery string-pad functio...
-> ->Xquery string-pad functio...
-> ->Xquery string-pad functio...
-> ->Xquery string-pad functio...
-> + DB to XML Data Source (2)
-> + XML Streaming not working (2)
-> + XQuery General Question (11)
-> + ERROR XQueryMediator Error dur... (2)
-> + Print Date in XML File (2)
-> + Aritmetic in Xquery (2)
-> + Use content of node as node na... (2)
-- Previous [181-200] [201-220] [221-240] Next
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
(Deleted User) Subject: Xquery string-pad function
Author: (Deleted User)
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
(Deleted User) Subject: Xquery string-pad function
Author: (Deleted User)
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
(Deleted User) Subject: Xquery string-pad function
Author: (Deleted User)
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

   
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.