Add documentation for attribute-axis 77/140477/2
authordanielhanrahan <daniel.hanrahan@est.tech>
Thu, 13 Mar 2025 14:40:57 +0000 (14:40 +0000)
committerdanielhanrahan <daniel.hanrahan@est.tech>
Thu, 13 Mar 2025 15:23:22 +0000 (15:23 +0000)
Issue-ID: CPS-2624
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: Iafa145d1fefbd26adc8786e4001d90883acf1463

docs/cps-path.rst

index eb203d8..cfaad3c 100644 (file)
@@ -1,6 +1,6 @@
 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
 .. http://creativecommons.org/licenses/by/4.0
-.. Copyright (C) 2021-2023 Nordix Foundation
+.. Copyright (C) 2021-2025 Nordix Foundation
 .. Modifications Copyright (C) 2023 TechMahindra Ltd
 
 .. DO NOT CHANGE THIS LABEL FOR RELEASE NOTES - EVEN THOUGH IT GIVES A WARNING
@@ -183,7 +183,7 @@ General Notes
 Query Syntax
 ============
 
-``( <absolute-path> | <descendant-path> ) [ <leaf-conditions> ] [ <text()-condition> ] [ <contains()-condition> ] [ <ancestor-axis> ]``
+``( <absolute-path> | <descendant-path> ) [ <leaf-conditions> ] [ <text()-condition> ] [ <contains()-condition> ] [ <ancestor-axis> ] [ <attribute-axis> ]``
 
 Each CPS path expression need to start with an 'absolute' or 'descendant' xpath.
 
@@ -310,3 +310,21 @@ The ancestor axis can be added to any CPS path query but has to be the last part
 **Limitations**
   - Ancestor list elements can only be addressed using the list key leaf.
   - List elements with compound keys are not supported.
+
+attribute-axis
+--------------
+
+The attribute axis can be added to a CPS path query at the end. It will return only distinct values of a specified leaf.
+
+**Syntax**: ``<cps-path> ( '/@' <leaf-name> )?``
+  - ``cps-path``: Any CPS path query.
+  - ``leaf-name``: The name of the leaf (attribute) for which values should be returned.
+
+**Examples**
+  - ``//categories/@name``
+  - ``//categories[@code='1']/books/@price``
+  - ``//books/ancestor::bookstore/@bookstore-name``
+
+**Notes**
+  - The output is a list of attribute-value pairs. For example, ``[{"name":"Kids"},{"name":"SciFi"}]``
+  - Only unique values will be returned. For example, if 3 books have a price of 5, then 5 will be returned only once.