skip to Main Content

I want to import products (categories) from XML.

Categories element is <type>RCA</type> where "RCA" is category.

There is multiple categories i want.

For single category i used "/product[contains(type, "RCA")]" although it worked it gave me all categories with word "RCA".

Also how can I filter multiple categories? When I did for example:

"/product[contains(type, "RCA" or type, "XLR" or "DVI" or "HDMI")]"

…it did not work.

2

Answers


  1. From this answer I gather that you’d want to use something like:

    /product[contains(type, "RCA") or contains(type, "someOtherType")]
    

    Not tested but worth a try.

    Login or Signup to reply.
  2. Try this:

    /product[type[contains('RCAXLRDVIHDMI',.)]]
    

    This uses contains the other way around.

    There might be a problem with /product (single slash). This normally will only select the root-element. If you want only child::product use it without any slash
    product or ./product. If you want all descendants use .//product or descendant::product

    If you have even more categories the XPath is safer with the spaces surrounded it wil only match these types and not types that are inside each other, like ONE and ONES

    /product[type[contains(' RCA XLR DVI HDMI ',concat(' ',.,' '))]]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search