Xpath in docx, having parentheses as contains attribute



using a library for docx manipulation, phpdocx.com, I stumbled upon a problem which I can't solve with my poor xpath and docx knowledge.


In phpdocx, there are so called block variables which are used to mark a complete block, for example



$BLOCK_foo.bar$
Here comes a value
$BLOCK_foo.bar$


In order to locate and remove such blocks, they (phpdocx) use the following xpath expression:



//w:p[w:r/w:t[text()[contains(.,"BLOCK_foo.bar")]]]


The respective docx snippet can be found here: http://ift.tt/1tA9TX1


So, I've debugged it and the above XPath query finds one node, w:p.


The first question, admittedly: why does it find only one match but there are actually two (the "starting" and the "ending" block). Besides, the BLOCK_ occurence is ripped because of that bookmark thingie. How does that work at all?


But the actual question I have is, I have, don't ask, a block name like $BLOCK_foo.bar(20).baz$.


The xpath for this one, respectively, is



//w:p[w:r/w:t[text()[contains(.,"BLOCK_foo.bar(20).baz")]]]


This does not work as expected, it finds two nodes (both w:p though); where, I cross-checked that,



//w:p[w:r/w:t[text()[contains(.,"BLOCK_foo.bar20.baz")]]]


..correctly works on $BLOCK_foo.bar20.baz, so I, at the end, think it's a problem with the occurrence of the parantheses in the expression? On the other hand, the contains() value is wrapped in quotes so I'd say that shouldn't be a problem; but I've read that single quotes for example might also make trouble in contains() expressions...


Do you have an idea what I can do here?


No comments:

Post a Comment