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>
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), ''))
};
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, " ")
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.