Search and replace: Use XPath in replace expression

Having trouble installing Oxygen? Got a bug to report? Post it all here.
ckirchho
Posts: 6
Joined: Thu Sep 30, 2010 12:16 pm

Search and replace: Use XPath in replace expression

Post by ckirchho »

Hello,

I have the following exemplary tei tagging structure:

Code: Select all

<text type="art_miscellanea" n="[212.1]" xml:id="ar212mi01">
...
<body>
<div type="misc_undef">...</div>
<div type="misc_undef">...</div>
I would like to insert an xml:id attribute to those div tags that consist of the xml:id attribute of the text tag plus an underscore and an counter.

Searching with an

Code: Select all

XPath //text[@type='art_miscellanea']/body/div[@type='misc_undef']
for the text

Code: Select all

type="misc_undef"
works. It would find the seacrhed text in children of those divs as well, but there are no children with such a type attribute.

Now I would like to replace that text with

Code: Select all

type="misc_undef" xml:id="<expression>"
And the expression has to be something like

Code: Select all

concat(parent::body/parent::text/@xml:id, '_', counter())
The counter could even be derived from the position of the div within the body tag.

Is there anything like this possible? Writing a transformation to do this would be an alternative, but I was wondering if XPath in replace expressions is supported somehow...

Best regards,

Christian Kirchhoff
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Search and replace: Use XPath in replace expression

Post by adrian »

Hello,

Unfortunately you cannot evaluate that XPath expression in context to use its result as a replace pattern. There is a messy way to do this with regular expressions but to be safe you should use an XSLT stylesheet or XQuery.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply