You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Requirement

we would like to bring support for contains operator in cps-path. 

contains() is a method in XPath expression. It is used when the value of any attribute changes dynamically, below are the examples,

Reference

CPS-1272


Issues & decisions


#

Issue

Notes 

Decision

1

In this example, we can identify the element by using leaf-name and leaf-value. In this cps-path expression leaf-name=lang and leaf-value=english.

sample json data :

{
   "test:bookstore":{
      "bookstore-name": "Chapters",
      "categories": [
         {
            "code": "01",
            "name": "SciFi",
            "books": [
               {
                  "authors": [
                     "Iain M. Banks"
                  ],
                  "lang": "english",
                  "price": "895",
                  "pub_year": "1994",
                  "title": "Feersum Endjinn"
               }
            ]
         },
         {
            "name": "kids",
            "code": "02",
            "books": [
               {
                  "authors": [
                     "Philip Pullman"
                  ],
                  "lang": "Science",
                  "price": "699",
                  "pub_year": "1995",
                  "title": "The Golden Compass"
               }
            ]
         }
      ]
   }
}

Syntax: <cps-path> ( contains '[@leafname,' <string-value> ']' )

Examples

  • //books[contains(@lang,'english')



2

In this example, we can identify the element by  using partial  value of the attribute. In this cps-path expression partial value ‘en’ is used in place of english and science

sample json data :

{
   "test:bookstore":{
      "bookstore-name": "Chapters",
      "categories": [
         {
            "code": "01",
            "name": "SciFi",
            "books": [
               {
                  "authors": [
                     "Iain M. Banks"
                  ],
                  "lang": "english",
                  "price": "895",
                  "pub_year": "1994",
                  "title": "Feersum Endjinn"
               }
            ]
         },
         {
            "name": "kids",
            "code": "02",
            "books": [
               {
                  "authors": [
                     "Philip Pullman"
                  ],
                  "lang": "Science",
                  "price": "699",
                  "pub_year": "1995",
                  "title": "The Golden Compass"
               }
            ]
         }
      ]
   }
}

Syntax: <cps-path> ( contains '[@leafname,'<string-partial value> ']' )

 Examples

  • //books[contains(@pub_year,'99')]


Here , it  search the books that contains  '99' as sub string value in attribute pub_year.


3

In this example, we can identify the element by using text() element and its value. In this cps-path expression leaf-name=title and leaf-value=The Golden Compass.

sample json data :

{
   "test:bookstore":{
      "bookstore-name": "Chapters",
      "categories": [
         {
            "code": "01",
            "name": "SciFi",
            "books": [
               {
                  "authors": [
                     "Iain M. Banks"
                  ],
                  "lang": "english",
                  "price": "895",
                  "pub_year": "1994",
                  "title": "Feersum Endjinn"
               }
            ]
         },
         {
            "name": "kids",
            "code": "02",
            "books": [
               {
                  "authors": [
                     "Philip Pullman"
                  ],
                  "lang": "Science",
                  "price": "699",
                  "pub_year": "1995",
                  "title": "The Golden Compass"
               }
            ]
         }
      ]

Syntax: <cps-path> (  contains '[@text(),' <string-value> ']' )

Examples

  • //books/title[contains(@text(),'The Golden')]

 Query format for contains keyword 

#

Query

Output

1

cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'title' like '%Feersum End%';

155 | /bookstore/categories[@code='01']/books[@title='Feersum Endjinn'] | {"lang": "en", "price": 895, "title": "Feersum Endjinn", "authors": ["Iain M. Banks"], "pub_year": 1994} |         4 |       154 |            5 |

2cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'lang' like '%en%';

155 | /bookstore/categories[@code='01']/books[@title='Feersum Endjinn']    | {"lang": "en", "price": 895, "title": "Feersum Endjinn", "authors": ["Iain M. Banks"], "pub_year": 1994}                                                                                                     |         4 |       154 |            5 |
 156 | /bookstore/categories[@code='01']/books[@title='Far Horizons']       | {"lang": "en", "price": 1099, "title": "Far Horizons", "authors": ["Rober Silverberg", "Joe Haldeman", "Orson Scott Card", "Ursula K. Le Guin", "Dan Simmons", "david Brin", "Greg Bear"], "pub_year": 1999} |         4 |       154 |            5 |

3cpsdb=# SELECT * FROM FRAGMENT WHERE anchor_id = 4 and attributes->>'pub_year' like '%99%';

153 | /bookstore/categories[@code='02']/books[@title='The Golden Compass'] | {"lang": "en", "price": 699, "title": "The Golden Compass", "authors": ["Philip Pullman"], "pub_year": 1995}                                                                                                 |         4 |       152 |            5 |
 155 | /bookstore/categories[@code='01']/books[@title='Feersum Endjinn']    | {"lang": "en", "price": 895, "title": "Feersum Endjinn", "authors": ["Iain M. Banks"], "pub_year": 1994}                                                                                                     |         4 |       154 |            5 |
 156 | /bookstore/categories[@code='01']/books[@title='Far Horizons']       | {"lang": "en", "price": 1099, "title": "Far Horizons", "authors": ["Rober Silverberg", "Joe Haldeman", "Orson Scott Card", "Ursula K. Le Guin", "Dan Simmons", "david Brin", "Greg Bear"], "pub_year": 1999} |         4 |       154 |            5 |

  • No labels