|
next
|
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>
|
next
|
Subject: 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, " "),"' ",
"'", local:string-pad("12" , 3, " "),"' ",
"'", local:string-pad("123", 3, " "),"' "), '')
Hope this helps
Ivan Pedruzzi
Stylus Studio Team
|
|
|
|