IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
  • 1.  counting all symbols "\"

    Posted 05/31/10 02:14 PM

    i’m looking for a function that counts all "" symbols.

    my xml-file looks like:

    <files>
    <file>
    <owner>quatsch</owner> 
    <name>beispieldatei2</name> 
    <size>1024</size> 
    <extension>.doc</extension> 
    <creationTime>22.05.2010 16:50</creationTime> 
    <lastWriteTime>22.05.2010 16:51</lastWriteTime> 
    <lastAccessTime>22.05.2010 16:52</lastAccessTime> 
    <path>D:\Dokumente\beispieldatei2.doc</path> 
    <parentDirectory>D:\Dokumente</parentDirectory> 
    <rootDirectory>D:\</rootDirectory> 
    <directory>D:\</directory> 
    </file>
    </files>

    function searched like:

    for $q in input()/files
    return (count-string($q/file/path, '\')

    returnvalue in this example: 2

    thanks for any input.


    #webMethods
    #API-Management
    #Tamino


  • 2.  RE: counting all symbols "\"

    Posted 05/31/10 02:49 PM

    See the following example:

    
    let $string:="1234\56789\1x3\45"
    return count
    (for $i in 1 to string-length($string)
    return substring($string,$i,1) [.="\"])

    or

    
    let $string:="1234\56789\1x3\45"
    let $matches:=(for $i in 1 to string-length($string) return substring($string,$i,1) [.="\"])
    return count ($matches)

    or even cleaner

    
    let $string:="1234\567891x3\45"
    let $chars:=(for $i in 1 to string-length($string) return substring($string,$i,1))
    return count ($chars [.="\"])

    #Tamino
    #API-Management
    #webMethods


  • 3.  RE: counting all symbols "\"

    Posted 05/31/10 04:14 PM

    Thanks a lot for the reply.

    I see, there is quit a better why than mine. In meantime i programmed a function:

    declare namespace functx = "...";
    declare function functx:index-of-string
    ( $arg as xs:string? ,
    $substring as xs:string )  as xs:integer* {
    
    if (contains($arg, $substring))
    then (string-length(substring-before($arg, $substring))+1,
    for $other in
    functx:index-of-string(substring-after($arg, $substring),
    $substring)
    return
    $other +
    string-length(substring-before($arg, $substring)) +
    string-length($substring))
    else ()
    } ;

    so I can call the function like:

    count(functx:index-of-string($path, '\'))

    #Tamino
    #API-Management
    #webMethods