OSb-XQuery-TypeConversion(decimal to int)

Hi all,
I need some help in Xquery Transformation
Source element type is decimal
target element type is int
I need to convert to decimal to int in Xquery.
Actually I tried like this way
<targetElement>{xs:int($sourceElement)}</targetElement>
<error>Error occurred while executing XQuery: {err}XP0021: "100.00": can not cast to {http://www.w3.org/2001/XMLSchema}integer: error: integer: Invalid integer value: 100.00. Either the XQuery is invalid or it contains custom XQuery functions. Try using the web test console to test this XQuery (Right click on the XQuery file and select Run As ->Run On Server) </error>
Can u help on this ,Which function do I need to use for type casting in Xquery.
Regards
Krishna.

It's tricky because when you convert from xs:string to xs:integer decimal point is not allowed... So you have to go around and convert to xs:decimal first...
<targetElement>{xs:int(xs:decimal($sourceElement))}</targetElement>
Hope this answers your question...
Cheers,
Vlad

Similar Messages

  • In OSB , xquery issue with large volume data

    Hi ,
    I am facing one problem in xquery transformation in OSB.
    There is one xquery transformation where I am comparing all the records and if there are similar records i am clubbing them under same first node.
    Here i am reading the input file from the ftp process. This is perfectly working for the small size input data. When there is large input data then also its working , but its taking huge amount of time and the file is moving to error directory and i see the duplicate records created for the same input data. I am not seeing anything in the error log or normal log related to this file.
    How to check what is exactly causing the issue here,  why it is moving to error directory and why i am getting duplicate data for large input( approx 1GB).
    My Xquery is something like below.
    <InputParameters>
                    for $choice in $inputParameters1/choice              
                     let $withSamePrimaryID := ($inputParameters1/choice[PRIMARYID eq $choice/PRIMARYID])                
                     let $withSamePrimaryID8 := ($inputParameters1/choice[FIRSTNAME eq $choice/FIRSTNAME])
                     return
                      <choice>
                     if(data($withSamePrimaryID[1]/ClaimID) = data($withSamePrimaryID8[1]/ClaimID)) then
                     let $claimID:= $withSamePrimaryID[1]/ClaimID
                     return
                     <ClaimID>{$claimID}</ClaimID>                
                     else
                     <ClaimID>{ data($choice/ClaimID) }</ClaimID>

    HI ,
    I understand your use case is
    a) read the file ( from ftp location.. txt file hopefully)
    b) process the file ( your x query .. although will not get into details)
    c) what to do with the file ( send it backend system via Business Service?)
    Also noted the files with large size take long time to be processed . This depends on the memory/heap assigned to your JVM.
    Can say that is expected behaviour.
    the other point of file being moved to error dir etc - this could be the error handler doing the job ( if you one)
    if no error handlers - look at the timeout and error condition scenarios on your service.
    HTH

  • OSB - XQuery - line 24, col 1 {err}FORG0005: expected 1 item, got 2 or mor

    In the below XQ, I am trying to learn making calls to local functions. I have tweaked my earlier XQ, which had a local variable defined [in xf:getCost() function] as XPath to Quantity. Now, I have modified the XQ to make a call to xf:getQty() from xf:getCost(), to get the desired Quantity.
    On executing the below code I get Error occurred while executing XQuery: line 24, column 1: {err}FORG0005: expected exactly one time, got 2+ items. Either the XQuery is invalid or .... Request Help
    xquery version "1.0" encoding "Cp1252";
    (:: pragma parameter="$anyType1" type="xs:anyType" ::)
    (:: pragma type="xs:anyType" ::)
    declare namespace xf = "http://tempuri.org/purchaseOrder/";
    declare function xf:getCost()
    as xs:double {
    let $po := <purchase-order>
    <red-tape/>
    <order-item product="p010" price="10.50" quantity="3"/>
    <order-item product="p020" price="18.10" quantity="8"/>
    <order-item product="p020" price="11.10" quantity="8"/>
    </purchase-order>
    let $s1 := $po/order-item/@price
    let $s2 := $po/order-item/@quantity
    let $s3 := sum(for $el at $i in $s1 return $s1[$i] * xf:getQty($i))
    return $s3
    declare function xf:getQty($index as xs:decimal)
    as xs:decimal {
    let $po := <purchase-order>
    <red-tape/>
    <order-item product="p010" price="10.50" quantity="3"/>
    <order-item product="p020" price="18.10" quantity="8"/>
    <order-item product="p020" price="11.10" quantity="8"/>
    </purchase-order>
    return ($po/order-item/@quantity[$index])
    xf:getCost()

    return ($po/order-item[$index]/@quantity)
    not
    return ($po/order-item/@quantity[$index])

  • OSB - XQuery - line 7, col 2: {err}FORG0005: expected exactly 1 item, got 0

    Hi,
    I am trying to execute the below sample XQuery. Eclipse designer does not show any error. However on executing the XQuery, I get the following error "+Error executing the XQuery transformation: line 7, column 2: {err}FORG0005: expected exactly one item, got 0 items+". Appreciate your help.
    xquery version "1.0" encoding "UTF-8";
    declare namespace xf = "http://tempuri.org/OSB%20Project%201/Ids/";
    declare function xf:Ids()
    as element() {*
    *     let $abc := <catalog><product dept="MEN"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Our favorite shirt!</desc></product></catalog>*
    *     for $product in $abc/catalog/product*
    *     let $name := $product/name*
    *     where $product/@dept = "ACC"*
    *     order by $name*
    *     return $name*
    xf:Ids()

    Thanks, for the answer.
    I just tweeked my XQuery:Var = $abc a little and ended up with same issue. Request your help again.
    xquery version "1.0" encoding "UTF-8";
    declare namespace xf = "http://tempuri.org/OSB%20Project%201/Ids/";
    declare function xf:Ids() as element(*)? {
    let $abc := +<catalog><product dept="MEN" xmlns="http://datypic.com/prod"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Ou<i>favorite</i> shirt! </desc></product><product dept="ACC"><number>563</number><name language="en">Floppy Sun Hat</name></product><product dept="ACC"><number>443</number><name language="en">Deluxe Travel Bag</name></product><product dept="MEN"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Ou<i>favorite</i> shirt! </desc></product><product dept="WMN"><number>557</number><name language="en">Fleece Pullover</name><colorChoices>navy black</colorChoices></product></catalog>+
    --(:<catalog><product dept="ACC"><number>784</number><name language="en">Cotton Dress Shirt</name><colorChoices>white gray</colorChoices><desc>Our favorite shirt!</desc></product></catalog>:)--
    for $product in $abc/product
    let $name := $product/name
    where $product/@dept = "ACC"
    order by $name
    return $name
    xf:Ids()

  • How to use typeswitch in osb xquery ?

    Hi all,
    I couldnt understand the syntax of the x query type switch used in osb.Can anybody kindly explain it or give links to examples.
    typeswitch (())
    case $case-var as element(*) return ()
    default ()
    1) what should be given inside the typeswitch (()) ?
    2) what should be given as this variable $case-var ?
    3) what is the meaning of sequence type element(*) ?
    4) Is the typeswitch in x query used to avoid multiple nested if or is it something else ?
    Thank you.
    Edited by: Arun Vikram on Jul 18, 2010 11:47 PM
    Edited by: Arun Vikram on Jul 19, 2010 12:00 AM

    Hi Arun,
    See the section "2.11 Operations on Datatypes" of below doc -
    http://www.w3.org/TR/2001/WD-xquery-20010607/
    typeswitch is explained with an example in this section. typeswitch is similar concept as "switch" in Java.
    1) what should be given inside the typeswitch (()) ?The expression whose dynamic type is being tested.
    2) what should be given as this variable $case-var ?Each CASE clause specifies the name of a type, which must be a subtype of the static type of the operand expression, followed by a RETURN expression.
    3) what is the meaning of sequence type element(*) ?Any XML node
    4) Is the typeswitch in x query used to avoid multiple nested if or is it something else ?As said,The typeswitch expression of XQuery allows users to write queries that are sensitive to dynamic type, yes it helps to avoid multiple nested if to fulfill this use case.
    Regards,
    Anuj
    Edited by: Anuj Dwivedi, TCS on Jul 19, 2010 12:32 PM

  • OSB XQuery Maps

    Greetings!
    1]. I use OSB 10.3 with Eclipse (OSB Workshop that comes with OSB 10.3 installabe) IDE for doing mapping.
    I draw lines from Source to Target structure in XQuery Transformation. I see the source code getting build. When I close the XQuery and open it again in the IDE, I see all the source to target lines in the design view disappear. However the source code is still there. Any ideas what might be wrong here?
    2] In my XQuery transformation target structure for elements when I mounse over I see the Nodename, Namespace prefix and Namespace URI. However for some elements I see the namespace URI but no namespace prefix. This is causing problem because in the source code and in the output it produces there are elements without namespace prefix rendering the output invalid. I cant think of why for some elements there are no namespace prefixes. Any advise?
    Only think I can think of is that the target structure seem to have a cyclic reference in the schema.. pls see below example. Is this a problem?
    <a:element1>
    <b:element2>
    <a:element3>
    </b:element>
    </a:element1>
    3] I generated XQuery using mapforce for a map and when I tried to use it in OSB, it errored stating Recursive XQueryies are not supported in OSB. Any thots?
    Thanks in advance

    +2] In my XQuery transformation target structure for elements when I mounse over I see the Nodename, Namespace prefix and Namespace URI. However for some elements I see the namespace URI but no namespace prefix. This is causing problem because in the source code and in the output it produces there are elements without namespace prefix rendering the output invalid. I cant think of why for some elements there are no namespace prefixes. Any advise?+
    Only think I can think of is that the target structure seem to have a cyclic reference in the schema.. pls see below example. Is this a problem?
    +<a:element1>+
    +<b:element2>+
    +<a:element3>+
    +</b:element>+
    +</a:element1>+
    Schema cyclic reference was causing the problem with empty namespace. I had to go in to the XQuery and manually add the namespace and prefic and qualify the elements. After this data gets mapped

  • OSB: xquery as input to xquery

    Hi
    i have stored an xml as xquery. <customer><name>swa</name><name>neh</name></customer>
    i have written another xquery (named result.xquery) which takes input from above xml and produces result. ex: if (data($customer/name)='swa' then 'osb' else '')
    i am assigning customer.xquery to a variable CUSTOMER and applying result transformation.
    since my xml (customer.xquery) is static and reside within OSB only, can i pass it to result.xquery without assigning it to CUSTOMER.
    In short can I pass an xquery as an input to another xquery?
    p.s.: Issue may seem trivial, but in my case i need to get quite a lot static xmls in code and i am instructed not to use java callout.

    In short can I pass an xquery as an input to another xquery?No. You cannot do so.
    i am assigning customer.xquery to a variable CUSTOMER and applying result transformation.Actually when you are assigning a XQuery into variable then OSB internally executes the XQuery and assigns the output of XQuery to the variable. So your variable does not actually hold the reference of the XQuery rather it holds the output of XQuery which you are passing as input to another XQuery.
    You may consider storing mappings into DB and use result caching feature with JCA DB adapter BS to retrieve the mapping's value at runtime.
    Regards,
    Anuj

  • OSB XQuery Issue

    Hi,
    I have an xml A containing 100 elements.
    I have an xml B containing 500 elements out of which 75 are mandatory while rest are optional.
    I am transforming from xml A to xml B using XQuery Transformation.
    While transforming, the mandatory ones in xml B are coming perfectly, but the optional ones are coming empty.
    For example:
    Incoming xml:
    <Name>
    <FirstName>John</FirstName>
    </Name>
    Expected Response:
    <NAME>
    <FNAME>John</FNAME>
    </NAME>
    If element <FirstName> is not present I get the empty node in my transformed xml.
    Eg.
    <NAME>
    <FNAME/>
    </NAME>
    Is there any way to avoid the empty node tag without specifically adding IF ELSE conditions.
    I am working on OSB 11.1.1.5
    Please help.
    Regards,
    Karthik

    Hi Karthik,
    There is no if/then/else in xquery, in xquery you use FLOWR.
    http://www.w3schools.com/xquery/xquery_flwor.asp
    <NAME>
    for $a in (/Name/FirstName)
    return
    <FNAME>data($a)</FNAME>
    </NAME>This will omit the FNAME if there is no FirstName...
    Note that I didn't verify the syntax, but I think you'll get the idea...
    Cheers,
    Vlad

  • OSB - XQuery - Sample Switch Case

    Hi,
    Can some one pls give me a sample XQ, with Switch Case statement in it, which [Syntax] works in OSB.
    Regards,
    Kaleem...

    I am really afraid that OSB 11g supports XQuery 1.0
    http://download.oracle.com/docs/cd/E21764_01/doc.1111/e15867/xquery.htm
    while the switch statement is introduced only in XQuery 1.1
    http://www.w3.org/TR/2009/WD-xquery-11-20091215/#id-switch
    for the time being, you will have to resort to a cascade of if - then - else :o(

  • OSB - Xquery - Eclipse shows warning when a repeating node is repeated

    Hi,
    I have a requirement where a node needs to be repeated. This cannot go into a FOR LOOP as data to be mapped to Target XSD, are constants.
    For this, I repeated the node, by just changing the data in the Name and Value field. When I do this, eclipse, shows me a warning and highlights all the lines. Next time, when I switch to design view and add some direct mapping, eclipse warns me and on proceeding, removes all the lines with warning. Any help, on how I should attempt to solve this issue.
    Give below is the example xquery. Target has the node defined as repeating.
    declare namespace ns1 = "http://abc.com/abc/source";
    declare namespace ns0 = "http://abc.com/abc/target";
    declare namespace xf = "http://tempuri.org/XSD/mapping/";
    declare function xf:mapping($requestMessage1 as element(ns1:requestMessage))
    +as element(ns0:target) {+
    +<ns0:targetHeader>+
    +<ns0:RepeatingNode>+
    +<ns0:Name>Name1</ns0:Name>+
    +<ns0:Value>XPATH to Source field</ns0:Value>+
    +</ns0:RepeatingNode>+
    +<ns0:RepeatingNode>+
    +<ns0:Name>Name2</ns0:Name>+
    +<ns0:Value>Hard coded Value</ns0:Value>+
    +</ns0:RepeatingNode>+
    +<ns0:RepeatingNode>+
    +<ns0:Name>Name3</ns0:Name>+
    +<ns0:Value>Hard coded Value</ns0:Value>+
    +</ns0:RepeatingNode>+
    +<ns0:RepeatingNode>+
    +<ns0:Name>Name4</ns0:Name>+
    +<ns0:Value>XPATH to Source field</ns0:Value>+
    +</ns0:RepeatingNode>+
    +<ns0:RepeatingNode>+
    +<ns0:Name>Name5</ns0:Name>+
    +<ns0:Value>Hard coded Value</ns0:Value>+
    +</ns0:RepeatingNode>+
    +</ns0:targetHeader>+
    Regards.
    Edited by: 874988 on Jul 25, 2011 7:01 PM

    design mode is OK until you start customizing by hand your xquery... if you muck around the mapping sometimes is lost.
    I would suggest you to complete your mapping by hand!

  • OSB Xquery mapping from multiple to single by separating its value(s).

    Hi,
    I have one requirement in OSB, can some one explain the implementation for this:
    I have one element which is of type unbound. I need to map this element to a single element and to append all the element values by separating each element value with a ';' before that I need to check whether this element(s) are present in the request then need to appened all these element values to a single element and at the end of this element need to append default values.
    Scenario:
    <student>
    <name>asd</name>
    <address>
    <street>street1</street>
    <street>street2</street>
    <street>street3</street>
    ||
    ||
    </address>
    to be mapped it to:
    <student>
    <field name="NAME">asd</field>
    <field name="ADDRESS">street1;street2;street3;default1;default2;default3</field>
    </student>
    Here need to check if street names are present in the request xml, if yes ned to assign it to ADDRESS as mentioned above whether street names present or not need to append the default values at the end to the ADDRESS field like
    <field name="ADDRESS">default1;default2;default3</field>
    Thanks in advance.

    Hi,
    Here's a query that should answer part of the question :
    <student>
      for $i in doc("doc.xml")/student/*
      return
       <field name="{upper-case(name($i))}">
        if ($i/*) then string-join($i/*, ";")
        else $i/text()
       </field>
    </student>It deals with all possible children of the student node. If a child has descendants, then their values are aggregated like you require, else just the child value is used.
    Additional question : where do the default values come from? Do we just have to "paste" the string "default1;default2;default3" as a whole?
    HTH.

  • ALSB (OSB) xquery support for fn:error

    Hi all,
    I've got a function which performs a check and eventually raise a fn:error
    In my IDE works fine and stop the transformation reporting the error, in Workshop it doesn't and complete the transformation anyway.
    Is there anything to enable? Is it supported? What other options I have?
    Thanks in advance

    Please refer -
    Re: XQuery fn:error function Issue
    Regards,
    Anuj

  • OSB XQuery transformation help in Proxy Service

    Hi,
    Need help in transformation of the below input to a proxy service
    <soapenv:Body  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <InputParams>
         <queryParams>
           <quer:query-params  xmlns:quer="http://www.example.org/QueryParams">
            <param name="test51" value="val3353" />
            <param name="test1" value="val2" />
            <param name="test3" value="val3" />
            <param name="test4" value="val4" />
            <param name="test1" value="val1" />
            <param name="test1" value="val11" />
            <param name="test8" value="val33" />
            <param name="test1" value="val34" />
            <param name="test8" value="val33" />
            <param name="test81" value="val33" />
            <param name="test1" value="val333" />
            <param name="test38" value="val33" />
           </quer:query-params>
         </queryParams>
       </InputParams>
    </soapenv:Body> and want to have the below output after running the below XQuery transformation
    <ns0:mparams>
      <ns0:param name="test1" value="val2" />
      <ns0:param name="test1" value="val1" />
      <ns0:param name="test1" value="val11" />
      <ns0:param name="test1" value="val34" />
      <ns0:param name="test1" value="val333" />
    </ns0:mparams>this is the xquery transformation file
    (:: pragma  parameter="$InputQuery" type="anyType" ::)
    (:: pragma bea:global-element-return element="ns0:mparams" location="../xsd/TargetParams.xsd" ::)
    declare namespace ns0 = "http://www.example.org/QueryParams";
    declare namespace xf = "http://tempuri.org/Simple/transformation/listparams/";
    declare function xf:listparams($InputQuery as element(*))
        as element(ns0:mparams) {
            <ns0:mparams>
                { $InputQuery/ns0:params/param[@name="test1"] }
            </ns0:mparams>
    declare variable $InputQuery as element(*) external;
    xf:listparams($InputQuery)and here is the input to the above .qs
    $body/InputParams/queryParams/qp:query-paramsbut it's the output is always empty and here is what it comes out no matter what the input I give even tried the below inputs but no use
    $body/InputParams/queryParams/qp:query-params
    $body/InputParams/queryParamshere is the output it always prints when logging in the log file
    <quer:mparams xmlns:quer="http://www.example.org/QueryParams"/>Any help is appreciated.
    Thanks

    $InputQuery/ns0:params/param[@name="test1"]Input doesn't have a ns0:params node ..so the xpath here should be $InputQuery/param[@name="test1"]

  • OSB, xquery and Assign issue

    Hello all
    I have an issue that I cannot quite understand...
    I have a very simple proxy service, that I would like to receive an xml of this form:
    <SO so_att1="soatt" xsi:noNamespaceSchemaLocation="Split.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <MLI mli_att1="mli1att">
              <LI li_att1="li1_att1">
                   <name>String</name>
                   <value>String</value>
                   <action>String</action>
              </LI>
              <LI li_att1="li2_att1">
                   <name>String</name>
                   <value>String</value>
                   <action>String</action>
              </LI>
              <LI li_att1="li3_att1">
                   <name>String</name>
                   <value>String</value>
                   <action>String</action>
              </LI>
              <LI li_att1="li4_att1">
                   <name>String</name>
                   <value>String</value>
                   <action>String</action>
              </LI>
              <LI li_att1="li5_att1">
                   <name>String</name>
                   <value>String</value>
                   <action>String</action>
              </LI>
              <name>String</name>
              <value>String</value>
              <action>String</action>
         </MLI>
    </SO>
    in order to transform it to a general data model of this form:
    <CDM>
         <Item so_att="soatt" mli_att="mli1att">
              <name>MLI1_name</name>
              <value>MLI1_value</value>
              <action>MLI1_action</action>
         </Item>
         <Item so_att="soatt" mli_att="mli1att" li_att="li1att">
              <name>LI1_name</name>
              <value>LI1_value</value>
              <action>LI1_action</action>
         </Item>
         <Item so_att="soatt" mli_att="mli1att" li_att="li2att">
              <name>LI2_name</name>
              <value>LI2_value</value>
              <action>LI2_action</action>
         </Item>
         <Item so_att="soatt" mli_att="mli1att" li_att="li3att">
              <name>LI3_name</name>
              <value>LI3_value</value>
              <action>LI3_action</action>
         </Item>
         <Item so_att="soatt" mli_att="mli1att" li_att="li4att">
              <name>LI4_name</name>
              <value>LI4_value</value>
              <action>LI4_action</action>
         </Item>
         <Item so_att="soatt" mli_att="mli1att" li_att="li5att">
              <name>LI5_name</name>
              <value>LI5_value</value>
              <action>LI5_action</action>
         </Item>
    </CDM>
    The common idea is to split the XML in to pieces with attributes inheritance. I have created 3 Assign actions. the 1st one has the xquery for seperating the MLI nodes with the correct attribues:
    for $i in (1 to fn:count($body/MLI))
    return
    <Item so_att1 = "{ data($body/@so_att1) }"
    mli_att1 = "{ data($body/MLI[$i]/@mli_att1) }">
    for $name in $body/MLI[$i]/name
    return
    <name>{ data($name) }</name>
    for $value in $body/MLI[$i]/value
    return
    <value>{ data($value) }</value>
    for $action in $body/MLI[$i]/action
    return
    <action>{ data($action) }</action>
    </Item>
    And it is saved in variable MLI
    The 2nd one is similar to this and saves to variable LI while the 3rd assign concats the variables like this: fn:concat('<CDM>', $MLI, $LI, '</CDM>') and saves in new variable...
    My problem comes, when I run on server the proxy. It is echoing (of course, cause there is no routing) but the incoming message passes only from third assign, ignoring the first and the second... Any idea why this is happening? The xqueries while tested inside the XQuery editor, works like charm...
    Thank you in advance

    Not sure if this is what you mean, but if you want to store elements in a variable during your XQuery you can use the "let" command.
    This way you can use them during your Xquery but it doesn't replace the Assign or Replace action in your message flow.
    let $x := 1
    let $y := $x + 1

  • OSB: XQuery to update a single node

    Hi,
    I have a large xml and I need to update just one element value in it? What options do I have in OSB message flow for it?
    Thank you
    Matt

    additional to Pierluigi his post
    you can use the array notation for the xml elements to just point immediately to right element
    ./orders/order[1] for example

Maybe you are looking for

  • Optimizing system for best performance/stability and a custom kernel

    I have ArchLinux running on a MacBook 4.1 (early 2008), and it's running very well so far. But I would like to optimize it for best performance and stability (but not at the cost of losing 'graphical interface' quality). I want to compile a custom ke

  • Satellite C660-1J2 hard disk failed

    I've got some problems First i can't write very well english Second and the true problem is that when i use my laptop it can't go to the windows seven because it can't boot the the hard disk The hard disk sounds oddly (a cyclic sound like "pchuk tak,

  • Firefox 7.0.1 won't install

    I did have 7.0.1 installed when it first came out. About a week ago I noticed a plug-in that was working fine had a slight 'glitch' in it (roboform 7.5.3). .long story so I'll skip to the chase...Decided to roll back Windows Vista 24 hours to see if

  • Toggle button problem..really urgent

    hi there.. i have a problem with my code and i hope someone can help me as i have a dateline to meet for my programme.. i have a set of 10 toggle buttons with 1 single actionlistener.. here is the code p3=new JPanel(); b1=new JPanel(); ActionListener

  • How do I change twm to fvwm2 window manager switch?

    Apple's X11 offering uses twm, which unfortunately I don't really like, and would like to replace it with fvwm2. I've tried this little trick, and boy, so far, no luck. Too bad I'm not a better systems admin. Does anyone have a howto on getting the A