Using XPath to refactor xml in oxygen
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 1
- Joined: Thu May 25, 2017 9:41 am
Using XPath to refactor xml in oxygen
Post by brentclark2003 »
have an xml doc that I am trying to reorganize and reformat. I have been trying to use oxygen's refactoring tool to wrap specific elements or group of elements. But instead of grouping the desired elements together, it just wraps each matched element individually. How do I write an XPath expression that targets and groups elements in this manner:
Using the Wrap Element tool to wrap the first 3 chunk elements together in an s element.
Going from this:
To this
Using the the XPath expression: /systems/system/chunk[position()<4] to select the first 3 chunk elements and enclose them with s tags. However when I run this in the refactoring command I get this:
Where it selects the proper chunks, but wraps each chunk individually. Please let me know if you have any suggestions on how to group all elements together in s tags. Or if I shouldn't even be using oxygen xml to accomplish this.
Using the Wrap Element tool to wrap the first 3 chunk elements together in an s element.
Going from this:
Code: Select all
<system>
<n>1057</n>
<chunk>X1</chunk>
<chunk>C6HF5</chunk>
<chunk>Pentafluorbenzol</chunk>
<chunk>C6H2F41,2,3,5-Tetrafluorbenzol</chunk>
<chunk>Äquimolare Mischung: </chunk>
<chunk/>
<r>[F5]</r>
<c>25°C</c>
<chunk>ΔHM = 1,84 cal/mol Misch. = 7,7 J/mol Misch.</chunk>
Code: Select all
<system>
<n>1057</n>
<s><chunk>X1</chunk>
<chunk>C6HF5</chunk>
<chunk>Pentafluorbenzol</chunk></s>
<chunk>C6H2F41,2,3,5-Tetrafluorbenzol</chunk>
<chunk>Äquimolare Mischung: </chunk>
<chunk/>
<r>[F5]</r>
<c>25°C</c>
<chunk>ΔHM = 1,84 cal/mol Misch. = 7,7 J/mol Misch.</chunk>
Code: Select all
<system>
<n>1057</n>
<s><chunk>X1</chunk></s>
<s><chunk>C6HF5</chunk></s>
<s><chunk>Pentafluorbenzol</chunk></s>
<chunk>C6H2F41,2,3,5-Tetrafluorbenzol</chunk>
<chunk>Äquimolare Mischung: </chunk>
<chunk/>
<r>[F5]</r>
<c>25°C</c>
<chunk>ΔHM = 1,84 cal/mol Misch. = 7,7 J/mol Misch.</chunk>
-
- Posts: 419
- Joined: Mon May 09, 2016 9:37 am
Re: Using XPath to refactor xml in oxygen
Post by sorin_carbunaru »
Hello,
oXygen does not have a default XML Refactoring operation for what you need. But you could define your own operation, if you'd like (see https://www.oxygenxml.com/doc/versions/ ... efactoring).
As the operation's script you could use Martin Honnen's XSLT from https://stackoverflow.com/questions/454 ... -in-oxygen:
You cannot write an XPath expression for the Wrap element operation to get what you want, because XPath only selects nodes from the XML, and cannot group them.
Regards,
Sorin Carbunaru
oXygen XML
oXygen does not have a default XML Refactoring operation for what you need. But you could define your own operation, if you'd like (see https://www.oxygenxml.com/doc/versions/ ... efactoring).
As the operation's script you could use Martin Honnen's XSLT from https://stackoverflow.com/questions/454 ... -in-oxygen:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="system/chunk[1]">
<s>
<xsl:copy-of select="., following-sibling::chunk[position() lt 3]"/>
</s>
</xsl:template>
<xsl:template match="system/chunk[2] | system/chunk[3]"/>
</xsl:stylesheet>
Regards,
Sorin Carbunaru
oXygen XML
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