Project

Profile

Help

Trying to use ends-with does not seem to work

Added by Roy Waxman over 6 years ago

Hello, I am evaluating saxon9pe.jar Trying to read xcode storyboard xml files: XPathFactory xpathFactory = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON); XPath xpath = xpathFactory.newXPath(); XPathExpression expr = xpath.compile("//*[ends-with(name(), 'view')]"); Object result = expr.evaluate(node, XPathConstants.NODESET); node will be the element Getting no nodes in return. When using contains function does work. What am i doing wrong? I am attaching storyboard file. Thanks Roy

Main.zip (2.38 KB) Main.zip Storyboard file

Replies (4)

Please register to reply

RE: Trying to use ends-with does not seem to work - Added by Michael Kay over 6 years ago

I don't see any elements there whose names end in "view". The only one that seems to come close is "tableView" - but ends-with() is case-sensitive. I wouldn't expect contains() to find anything either.

RE: Trying to use ends-with does not seem to work - Added by Roy Waxman over 6 years ago

Hello, Thank u for your reply. I am using this site for evaluation: http://videlibri.sourceforge.net/cgi-bin/xidelcgi And in that site it wasnt case-sensitive. I fixed my expression to /[ends-with(name(), 'View')] But then it returned both tableViewCellContentView and tableView Since i wanted only tableView i used now: //*[ends-with(name(), 'View')] In the site it worked fine. With Saxon code, not so much. The result list was empty. Any ideas? Thanks Roy

RE: Trying to use ends-with does not seem to work - Added by Michael Kay over 6 years ago

Technically, the ends-with() function uses the default collation defined in the static context, and it's possible that the demo site you are using, because it is focused on searching HTML, has chosen to configure it with a default collation that's case-blind. This wouldn't be non-conforming, but it's an unusual choice, especially as it's not mentioned on the query page. You can achieve the same effect with Saxon by explicitly choosing a different default collation in your API that issues the query.

The query @//[ends-with(name(), 'View')]@ will only select elements that are grandchildren of the root note. If you run it on a tree where tableViewController is the outermost element then it will select the tableView elements, but if tableViewController is deeper in the tree then it won't: you should use a path starting with "." rather than "/" to select from the context node when this is not the root.

RE: Trying to use ends-with does not seem to work - Added by Roy Waxman over 6 years ago

Hello,

Thanks!

I now understand that although i gave the function an element who was the root element it still was not considered as the root. So using "./*[ends-with(name(), 'View')]" worked nicely.

Thanks

Roy

    (1-4/4)

    Please register to reply