How to delete an attribute from some elements selected by XPath?
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 2
- Joined: Tue Aug 02, 2016 6:46 pm
How to delete an attribute from some elements selected by XPath?
I have an XML document which contains structures such as this one:
Now from all Elements "a" I want to delete the attribute "x" if the text of "Code" has no lines with more than 10 characters. Or in short: I want to delete
from my document.
If I enter the above XPath-Expression into the XPath-Search box I only get a single result: The attribute that I want to delete.
In the menu, I found the Option Tools->XML Refactoring->Attributes->Delete attribute. I can specify an XPath expression there from which an attribute can be deleted. Great! Except that my conditions are completely ignored. Oxygen will always delete all attributes "x" in the whole document. It will even remove the attribute "x" from "<b x="" />". It feels like the XPath is completely ignored. However if I supply an XPath that yields zero nodes in the whole document, no changes are performed.
What is going on there and how can I do what I would like to do?
Code: Select all
<a x="">
<Code>short</Code>
</a>
<a x="">
<Code>looooooonnnngggggggg</Code>
</a>
Code: Select all
//a[Code[not(matches(text(), '[^\n]{10,}'))]]/@x
If I enter the above XPath-Expression into the XPath-Search box I only get a single result: The attribute that I want to delete.
In the menu, I found the Option Tools->XML Refactoring->Attributes->Delete attribute. I can specify an XPath expression there from which an attribute can be deleted. Great! Except that my conditions are completely ignored. Oxygen will always delete all attributes "x" in the whole document. It will even remove the attribute "x" from "<b x="" />". It feels like the XPath is completely ignored. However if I supply an XPath that yields zero nodes in the whole document, no changes are performed.
What is going on there and how can I do what I would like to do?
-
- Posts: 404
- Joined: Thu Aug 21, 2003 11:36 am
- Location: Craiova
- Contact:
Re: How to delete an attribute from some elements selected by XPath?
Post by radu_pisoi »
Hi,
Thank you for reporting this problem.
It seems to be an issue in the XSLT stylesheet used to implement this operation. We already fixed this problem and the next minor bug fixes release will include a fix for it.
Meanwhile, you can fix it in your distribution by opening the file:
and replace the code
with code
Thank you for reporting this problem.
It seems to be an issue in the XSLT stylesheet used to implement this operation. We already fixed this problem and the next minor bug fixes release will include a fix for it.
Meanwhile, you can fix it in your distribution by opening the file:
Code: Select all
{oXygenInstallDir}/refactoring/delete-attribute.xsl
Code: Select all
<xsl:if test="not(.=$attributes)">
<xsl:copy/>
</xsl:if>
Code: Select all
<xsl:if test="not(. intersect $attributes)">
<xsl:copy/>
</xsl:if>
Radu Pisoi
<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: 7
- Joined: Tue Aug 23, 2016 8:08 pm
Re: How to delete an attribute from some elements selected by XPath?
You could also use xquery update for tasks like this.
In the xquery builder select saxon EE and in settings check "enable xq update" and "use linked tree model" and enter the code
In the xquery builder select saxon EE and in settings check "enable xq update" and "use linked tree model" and enter the code
Code: Select all
delete nodes doc(<your-document>)/<your-xpath>
-
- Posts: 404
- Joined: Thu Aug 21, 2003 11:36 am
- Location: Craiova
- Contact:
Re: How to delete an attribute from some elements selected by XPath?
Post by radu_pisoi »
Hi,
Yes, you are right, you can use XQuery update technology to update XML files. The XML Refactoring tool is implemented by running an XQuery update or XSLT operation over a set of XML files.
However, the XML Refactoring tool has some advantages as follow:
Yes, you are right, you can use XQuery update technology to update XML files. The XML Refactoring tool is implemented by running an XQuery update or XSLT operation over a set of XML files.
However, the XML Refactoring tool has some advantages as follow:
- The DOCTYPE will be preserved.
- The DTD entities will be preserved as they are in the original document when the document is saved.
- The attribute values will be kept in their original form without being normalized.
- The spaces between attributes are preserved. Basically, the spaces are lost by a regular XML serialization since they are not considered important.
Radu Pisoi
<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)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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