This discussion is archived
4 Replies Latest reply: Sep 5, 2011 4:07 AM by 760337 RSS

How to return unique value from xquery for by searching list of values

760337 Newbie
Currently Being Moderated
Hi

My response is ProductList and ItemList. Based on the passed in Item/Type the xquery should check the following conditions are return unique value

If passed in value exists then
     return "exists"
else if (count(item)>5) then
return "maxLimit"
else
"notExist"

<ProductIdentificationResponse>
<!-- LIST OF PRODUCTS -->
<ProductList>
     <Product>
     <!-- LIST OF ITEMS -->
     <ItemList>
          <Item>
          <Type>ITM22</Type>
<Value>5555</Value>
</Item>
          
     <Item>
<Type>ITM22</Type>
<Value>6666</Value>
</Item>
     
<Item>
<Type>ITM22</Type>
<Value>7777</Value>
</Item>

     </ItemList>
</Product>
</ProductList>
</ProductIdentificationResponse>



I have return the xquery as follows but not working

for $x in $ProductIdentificationResponse1/ProductList/Product/ItemList/Item
          return
               if ($passedParam/text() = $x/Value/text()) then
          ( "Exists" )
               else if (count( $ProductIdentificationResponse1/ProductList/Product/ItemList/Item) > 5) then
                    ("maxLimit")
               else
                    ("notExist")          
};


Any help will be appreciated

Thank you

Edited by: user11310683 on Sep 2, 2011 4:25 AM
  • 1. Re: How to return unique value from xquery for by searching list of values
    tsuji Journeyer
    Currently Being Moderated
    [0] First of all suppose the namespaces (corresponding to the prefixes v11, v12, v13) are setup in the response, supposedly somewhere in the ancestor of ProductIdentificationResponse just because no where is shown. Figuratively, it can be just as well like this.
    <v11:ProductIdentificationResponse
        xmlns:v11="your-namespace-uri-for-v11"
        xmlns:v12="your-namespace-uri-for-v12"
        xmlns:v13="your-namespace-uri-for-v13">
    <!-- LIST OF PRODUCTS -->
    <!-- etc etc... -->
    </v11:ProductIdentificationResponse>
    [1] Then, in the xqery, you've to have declarations, in the prolog, of the same with the prefixes not necessarily coincide with what used in the Response. To simplify the matter and remain concrete, let say you use the same prefixes to the letter.
    declare namespace v11="your-namespace-uri-for-v11";
    declare namespace v12="your-namespace-uri-for-v12";
    declare namespace v13="your-namespace-uri-for-v13";
    [2] With those done, your xpath will appear with fully qualified names... like this.
    for $x in $ProductIdentificationResponse1/v11:ProductList[1]/v11:Product/v12:ItemList[1]/v13:Item
    return
    if ($passedParam/text() = $x/v13:Value/text()) then
    ( "Exists" )
    else if (count( $ProductIdentificationResponse1/v11:ProductList[1]/v11:Product/v12:ItemList[1]/v13:Item) > 5) then
    ("maxLimit")
    else
    ("notExist") 
    };
    That's the idea.

    edit notes:
    Since op had edited his/her original post - well after I posted my entry - in grand scale and changed some very essential ingredients rendering my post potentially incomprehensible, I feel obliged to quote the original post here in below.

    user11310683 wrote:
    >
    Hi
    My response is ProductList and ItemList. Based on the passed in Item/Type the xquery should check the following conditions are return unique value

    If passed in value exists then
    return "exists"
    else if (count(item)>5) then
    return "maxLimit"
    else
    "notExist"

    <v11:ProductIdentificationResponse>
    <!-- LIST OF PRODUCTS -->
    <v11:ProductList>
    v11:Product>
    <!-- LIST OF ITEMS -->
    <v12:ItemList>
    <v13:Item>
    <v13:Type>ITM22</v13:Type>
    <v13:Value>5555</v13:Value>
    </v13:Item>

    <v13:Item>
    <v13:Type>ITM22</v13:Type>
    <v13:Value>6666</v13:Value>
    </v13:Item>

    <v13:Item>
    <v13:Type>ITM22</v13:Type>
    <v13:Value>7777</v13:Value>
    </v13:Item>

    </v12:ItemList>
    </v11:Product>
    </v11:ProductList>
    </v11:ProductIdentificationResponse>

    I have return the xquery as follows but not working

    for $x in $ProductIdentificationResponse1/ProductList[1]/Product/ItemList[1]/Item
    return
    if ($passedParam/text() = $x/Value/text()) then
    ( "Exists" )
    else if (count( $ProductIdentificationResponse1/ProductList[1]/Product/ItemList[1]/Item) > 5) then
    ("maxLimit")
    else
    ("notExist")
    };

    Any help will be appreciated
    Thank you
    >

    Edited by: tsuji on Sep 3, 2011 12:29 AM
  • 2. Re: How to return unique value from xquery for by searching list of values
    760337 Newbie
    Currently Being Moderated
    Updated my post

    Edited by: user11310683 on Sep 2, 2011 4:28 AM
  • 3. Re: How to return unique value from xquery for by searching list of values
    tsuji Journeyer
    Currently Being Moderated
    If you decided there is no namespace attached to the document and the input variable $passedParam (the nature of which is hidden), you have then to verify that it is some kind of element type, otherwise you can't reasonably expect to $passedParam/text() to mean anything. In view of you editing namespace at will like that, I cannot be sure how much you can make a sense out of what said. I can give you a typical $passedParam so that you can have a test with positive result.
    let $passedParam := document{<data>5555</data>}/data
    Go ahead with it and test the output.
  • 4. Re: How to return unique value from xquery for by searching list of values
    760337 Newbie
    Currently Being Moderated
    Thank you.... As you said its namespace issue

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points