grammar CpsPath ;
-cpsPath : ( prefix | descendant ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? EOF ;
+cpsPath : ( prefix | descendant ) multipleLeafConditions? textFunctionCondition? containsFunctionCondition? ancestorAxis? attributeAxis? EOF ;
slash : SLASH ;
+attributeAxis : SLASH AT leafName ;
+
ancestorAxis : KW_ANCESTOR_AXIS_PREFIX ancestorPath ;
ancestorPath : yangElement ( slash yangElement)* ;
normalizedXpathBuilder.substring(startIndexOfAncestorSchemaNodeIdentifier));
}
+ @Override
+ public void exitAttributeAxis(final CpsPathParser.AttributeAxisContext ctx) {
+ final String attributeName = ctx.leafName().getText();
+ normalizedXpathBuilder.append("/@").append(attributeName);
+ cpsPathQuery.setAttributeAxisAttributeName(attributeName);
+ }
+
@Override
public void exitTextFunctionCondition(final TextFunctionConditionContext ctx) {
cpsPathQuery.setTextFunctionConditionLeafName(ctx.leafName().getText());
private String descendantName;
private List<LeafCondition> leafConditions;
private String ancestorSchemaNodeIdentifier = "";
+ private String attributeAxisAttributeName = "";
private String textFunctionConditionLeafName;
private String textFunctionConditionValue;
private List<String> booleanOperators;
return !(ancestorSchemaNodeIdentifier.isEmpty());
}
+ /**
+ * Has attribute axis been included in cpsPath.
+ *
+ * @return boolean value.
+ */
+ public boolean hasAttributeAxis() {
+ return !(attributeAxisAttributeName.isEmpty());
+ }
+
/**
* Have leaf value conditions been included in cpsPath.
*
then: 'the query has the correct default properties'
assert result.cpsPathPrefixType == ABSOLUTE
assert result.hasAncestorAxis() == false
+ assert result.hasAttributeAxis() == false
assert result.hasLeafConditions() == false
assert result.hasTextFunctionCondition() == false
assert result.hasContainsFunctionCondition() == false
'parent & child with multiple OR operators' | '/parent/child[@key1=1 or @key2="abc" or @key="xyz"]/child2' || "/parent/child[@key1='1' or @key2='abc' or @key='xyz']/child2"
'parent & child with multiple AND/OR combination' | '/parent/child[@key1=1 and @key2="abc" or @key="xyz"]/child2' || "/parent/child[@key1='1' and @key2='abc' or @key='xyz']/child2"
'parent & child with multiple OR/AND combination' | '/parent/child[@key1=1 or @key2="abc" and @key="xyz"]/child2' || "/parent/child[@key1='1' or @key2='abc' and @key='xyz']/child2"
+ 'attribute axis' | '/parent/child/@key' || '/parent/child/@key'
}
def 'Parse xpath to form the Normalized xpath containing #scenario.'() {
'/test[@name2="value2" and @name1="value1"]' || 'name2' | 'name1'
}
+ def 'Cps Path using attribute axis.'() {
+ when: 'the cps path is parsed'
+ def result = CpsPathQuery.createFrom(cpsPath)
+ then: 'the query has the correct properties for attribute axis'
+ assert result.hasAttributeAxis() == expectAttributeAxis
+ assert result.attributeAxisAttributeName == expectedAttributeName
+ where: 'the following data is used'
+ cpsPath || expectAttributeAxis | expectedAttributeName
+ '/test' || false | ''
+ '/test/@id' || true | 'id'
+ '/test[@id="id"]' || false | ''
+ '/test[@id="id"]/@id' || true | 'id'
+ '//test/ancestor::root' || false | ''
+ '//test/ancestor::root/@xyz' || true | 'xyz'
+ }
+
}