0

I 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:

 <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>

To this:

<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>

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:

<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>

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.

1 Answers1

0

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 oXygen user's guide). And you could use Martin Honnen's XSL (the first comment to your post) as the operation's script.