skip to Main Content

I want to import all products filtering these they applied all 3 criteria:

1) they are in stock (DIM)

2) stock is more than 3 pcs (stock_indicator)

3) and they belong to one (any) of these groups 1 or 4

I want all 3 criteria, but in 3rd any of these options

i.e.:
/product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]

The above does not returns any product, like no product have all these requirements.

What am I doing wrong?

Dim = availability

XML sample:
enter image description here

2

Answers


  1. /product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]
    

    First of all your XPath assumes that all product elements are at root level, which would not make for a well-formed XML document; the all should be wrapped in some element.

    If that is no problem in your environment (since we do not know the whole setup from your question) probably the most prominent problem in your XPath is that you try to compare the value of stock_indicator against a xs:integer but in fact your data sample encodes them as xs:string.

    Consequently

    stock_indicator[1] > 3
    

    will always return false

    Try

    stock_indicator[1]/number() > 3
    

    or

    number(stock_indicator[1]) > 3
    

    instead.

    Nevertheless depending on the data structure (e.g. multiple stock_indicatorelements in one product [whatever that might mean]) this could return false positives.

    Login or Signup to reply.
  2. You can use the following XPath to filter the products :

    //product[availability="1"][stock_indicator>3][group/id=1 or group/id=4]
    
    • // at the beginning as stated by @Benjamin W. Bohl to catch all products
    • availability is used instead of "Dim"
    • cleaner syntax used for predicates
    • no position indexes used ([1]) assuming you only have 1 availability, 1 stock_indicator, 1 id per group in each product

    XML used to test.

    XPath :

    XP

    XML is filtered (2 of the 4 products fulfill the conditions) :

    FilterXML

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search