Search and replace using regex and xpath
Oxygen general issues.
-
- Posts: 13
- Joined: Sat Jun 23, 2018 12:52 am
Search and replace using regex and xpath
Hi there,
I need to add a bold tag (b) to callout numbers that have the form (1), (2), (n).
The regex would be something like:
The tag has already been applied without consistency, so I'm trying to finish the job so to speak. But I don't want to apply the tag if it's already there.
Since Oxygen can do a search and replace using Xpath, I looked at how to restrict the search and replace to callouts that don't already have the tag. It would look something like:
I'm kind of missing the next step: how to actually perform the search and replace operation?
Thank you for your help.
I need to add a bold tag (b) to callout numbers that have the form (1), (2), (n).
The regex would be something like:
Code: Select all
\(\d+\)
Since Oxygen can do a search and replace using Xpath, I looked at how to restrict the search and replace to callouts that don't already have the tag. It would look something like:
Code: Select all
[not(ancestor::b)]
Thank you for your help.
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Search and replace using regex and xpath
Hi,
First, [not(ancestor::b)] will not work, because XPath actually comes first (it defines the searched regions) and you have at least one parent element that wraps your text (so it includes both text and b tag) and that one doesn't have the b ancestor. So XPath will match that parent element and still find the text wrapped in b tag within that region.
Instead, search for: (this means it shouldn't be preceded by <b> tag).
replace with: and leave XPath empty (or filter by the parent element, if you need it to be more precise).
This works with both Find/Replace and Find/Replace in Files.
Regards,
Adrian
First, [not(ancestor::b)] will not work, because XPath actually comes first (it defines the searched regions) and you have at least one parent element that wraps your text (so it includes both text and b tag) and that one doesn't have the b ancestor. So XPath will match that parent element and still find the text wrapped in b tag within that region.
Instead, search for:
Code: Select all
(?<!<b>)\(\d+\)
replace with:
Code: Select all
<b>$0</b>
This works with both Find/Replace and Find/Replace in Files.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service