Adding Matching Tags using XML Refactoring

Questions about XML that are not covered by the other forums should go here.
binar
Posts: 16
Joined: Wed Apr 10, 2019 7:43 pm

Adding Matching Tags using XML Refactoring

Post by binar » Wed Jun 05, 2019 7:57 pm

Greetings,
I need to add opening and closing "para" tags to the code shown in Example #1 which exists in many different ICN number variations and across many separate XML files. Example #2 shows the result I need OxygenXML to deliver with the opening and closing "para" tags correctly inserted:

EXAMPLE #1 – Missing opening and closing <para> tags:

Code: Select all

<symbol id="ACQDS017" infoEntityIdent="ICN-XYZ-DE-A000202-L-04939-02028-A-01-1" />
EXAMPLE #2 – <para> tags correctly inserted:

Code: Select all

<para><symbol id="ACQDS019" infoEntityIdent="ICN-XYZ-DE-A000202-L-04939-02327-A-01-1" /></para>
The XML Refactoring dialog window shows seven operations for Elements. The one I am choosing to use is the "Insert Element" option which inserts a new element at a specific location. What is the correct data I need to insert into the fields shown below so I can get the result shown in Example #2 with opening and closing "para" tags correctly inserted?

XML Refactoring - Insert Element Dialog Window

Element
Local Name: ??????? (tried "para" and it did not work)
Namespace: ??????? (don't understand)

Location
XPath: ??????????? (tried "entry/para" and did not work)

For "Scope" I select "Current File".
For ""Filters" I checkmark "Restrict to know XML file types only.
Then when I select "PREVIEW" I get the message below:

"Could not find any resources that would be affected by this operation."

Additionally, how do I instruct OxygenXML to skip over all Example #2 scenarios already existing in any XML file? Where is the control for to set that up?

Lastly does this operation require one use code similar to what is shown below which I used to make global changes to attributes ? (Covered in previous post).

Code: Select all

Find with   (.*)[^*]$
Replace with  $1*

OR

Find with  (.*)([^*])$
Replace with  $1$2*
Any help I can get that will clarify for me how to make this kind of XML Refactoring operation work successfully will be greatly appreciated. Thank you.

Radu
Posts: 6285
Joined: Fri Jul 09, 2004 5:18 pm

Re: Adding Matching Tags using XML Refactoring

Post by Radu » Thu Jun 06, 2019 11:22 am

Hi,

You should try to use the "Wrap element" pre-defined XML refactoring action.
The target element should be "symbol" and the wrapper element should be "para" with empty namespace (if your XML does not specify a namespace).

About these remarks:
Additionally, how do I instruct OxygenXML to skip over all Example #2 scenarios already existing in any XML file? Where is the control for to set that up?
You can set the "Target element" value to be something like symbol[not(parent::para)] so that it matches any symbol not already inside a paragraph. element
Lastly does this operation require one use code similar to what is shown below which I used to make global changes to attributes ? (Covered in previous post).
No, you do not seem to want to modify only a part of some text or attribute value.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

binar
Posts: 16
Joined: Wed Apr 10, 2019 7:43 pm

Re: Adding Matching Tags using XML Refactoring

Post by binar » Tue Jun 11, 2019 6:14 am

Radu,
Thank you for your help with the "Wrap Element" XML Refactoring action. I followed your instructions and it performed flawlessly. I am very thankful OxygenXML Editor comes included with this predefined action because it is a big time saver. Additionally, I have a question regarding Custom XML Refactoring Actions. To the best of your knowledge, does OxygenXML make available to customers what I define as a "Custom XML Refactoring Actions Library Pack"? If yes I would be interested in obtaining such a Library Pack because I think it will make great learning material for me to pick up XSL template authoring skills. In short, I hope someone in your organization has put together such a collection. Again, thanks for your help with this matter.

sorin_carbunaru
Site Admin
Posts: 226
Joined: Mon May 09, 2016 9:37 am

Re: Adding Matching Tags using XML Refactoring

Post by sorin_carbunaru » Tue Jun 11, 2019 1:47 pm

Hello,

I don't know if this is exactly what you are looking for, but in oXygen's installation directory there is the "refactoring" sub-folder where quite a few operations are defined (many of them in both XSLT and XQuery Update), and can be used as learning material.

You could also take a look inside the "frameworks\dita\refactoring" subfolder for some DITA-specific operations :).

Best wishes,
Sorin C.

P.S. - Radu had to take a few days off

binar
Posts: 16
Joined: Wed Apr 10, 2019 7:43 pm

Re: Adding Matching Tags using XML Refactoring

Post by binar » Fri Jun 14, 2019 12:11 am

Hi Sorin,
Thank you for your post. I looked in the folder you specify and I could not find any library of XSL templates for use in XML Refactoring operations. I also expanded my search to my entire OxygenXML installation directory and I was still unable to find such a library.

Nevertheless, I think I found what I am looking for in the OxygenXML Github website in the link below:

https://github.com/oxygenxml/dita-refactoring-examples

I would like to say "Thank You" to the person in your team that uploaded those examples to your Github website. It is useful training related material for those wanting to learn more about Refactoring.

Post Reply