Find text OUTSIDE specific element
Oxygen general issues.
-
- Posts: 4
- Joined: Mon May 04, 2015 5:57 pm
Find text OUTSIDE specific element
Post by kirstendehaan »
Hi there,
is it possible, using XPath in the Find/Replace dialog, to find and replace text that is OUTSIDE a specific element?
For example, in a certain file I would like to find all instances of φ that are not marked as <span class="dummy-formula">, and then replace them with <span class="dummy-formula">φ</span>.
So far, I have only been able to get XPath to find text INSIDE certain elements (for example: //span[@class='dummy-formula']) but now I need to do exactly the opposite. Is this possible?
Many thanks,
Kirsten
is it possible, using XPath in the Find/Replace dialog, to find and replace text that is OUTSIDE a specific element?
For example, in a certain file I would like to find all instances of φ that are not marked as <span class="dummy-formula">, and then replace them with <span class="dummy-formula">φ</span>.
So far, I have only been able to get XPath to find text INSIDE certain elements (for example: //span[@class='dummy-formula']) but now I need to do exactly the opposite. Is this possible?
Many thanks,
Kirsten
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find text OUTSIDE specific element
Hi,
You can use an XPath that looks for text whose parent is NOT span:
Or you can go further and ensure that the text is not nested inside other elements that are inside a 'span', so check that its ancestors do not include span:
You can also add the @class atribute check for the span element.
Regards,
Adrian
You can use an XPath that looks for text whose parent is NOT span:
Code: Select all
//text()[not(parent::span)]
Code: Select all
//text()[not(ancestor-or-self::span)]
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
-
- Posts: 4
- Joined: Mon May 04, 2015 5:57 pm
-
- Posts: 4
- Joined: Mon May 04, 2015 5:57 pm
Re: Find text OUTSIDE specific element
Post by kirstendehaan »
Hi Adrian,
thanks again for the reply.
However, I have a follow-up question:
I need to find the instances of φ in my files that are not in any element with class="dummy-formula". In our files, certain parts have been marked as mathematical formules using <span class="dummy-formula"> or <p class="dummy-formula">.
I need to find the instances that have not been marked as formulas so I can correct any mistakes. Is it possible to do this by adjusting the solution you gave me? I have tried but failed.
Thanks!
Kirsten
thanks again for the reply.
However, I have a follow-up question:
I need to find the instances of φ in my files that are not in any element with class="dummy-formula". In our files, certain parts have been marked as mathematical formules using <span class="dummy-formula"> or <p class="dummy-formula">.
I need to find the instances that have not been marked as formulas so I can correct any mistakes. Is it possible to do this by adjusting the solution you gave me? I have tried but failed.
Thanks!
Kirsten
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Find text OUTSIDE specific element
Hi,
This looks for text nodes that do not have ancestor elements with the @class="dummy-formula" attribute. If you only expect the attribute to be directly on the parent element, use parent:: instead of ancestor-or-self::.
Regards,
Adrian
Here's what you need. This also looks in ancestor elements (not just in parent elements):kirstendehaan wrote:I need to find the instances of φ in my files that are not in any element with class="dummy-formula". In our files, certain parts have been marked as mathematical formules using <span class="dummy-formula"> or <p class="dummy-formula">.
Code: Select all
//text()[not(ancestor-or-self::*[@class="dummy-formula"])]
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