Inserting a block of text into every record

Questions about XML that are not covered by the other forums should go here.
akyrios
Posts: 4
Location: Moscow, Idaho

Inserting a block of text into every record

Fri Aug 16, 2013 9:49 pm

Another entry in the "this may be really obvious" series. I have a block of text for contact information metadata that I'd like to insert in each of several thousand records. I can't use a simple copy and paste, because I want to put the block after an element that appears more than once in each record (and I only want the block once in each). Is there a simple insert function that could help me do this?
adrian
Posts: 2453

Re: Inserting a block of text into every record

Wed Aug 21, 2013 3:12 pm

Hello,

I'm not sure if this a general XML question or an Oxygen specific one.

For general XML processing you can use an XSLT stylesheet tailored to your particular problem. I don't have enough details for your particular problem to provide a solution. The usual solution involves a customized copy stylesheet that alters specific content while copying the rest.

In Oxygen (apart from the XSL solution) this can also be accomplished with the Find/Replace tools with the help of the XPath filter and some light regular expressions. This is not exactly XML specialized, it's a text replacement tool, but it is XML-aware.

If you provide more details about the name of the element and where exactly you want to insert the text I can offer a more specific solution.

e.g. To insert a block of text after the end of the last "tag" from "record"
Text to find: </tag>
Replace with: $0block of text
XPath: //record//tag[last()]
Options: Regular expression

The result will be "</tag>block of text".

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
akyrios
Posts: 4
Location: Moscow, Idaho

Re: Inserting a block of text into every record

Fri Aug 23, 2013 12:33 am

Ok, I couldn't get that to work. When I specified that XPath, it seems to have broken the search. It can't find the search text at all, let alone find and replace it. I was hoping to do this through Find/Replace rather than an XSLT. Is there not a way to just insert text at a certain line in a document?
akyrios
Posts: 4
Location: Moscow, Idaho

Re: Inserting a block of text into every record

Fri Aug 23, 2013 2:30 am

I could also solve this if I could include line breaks in a Find/Replace in Files search. I've got a working general Find/Replace setup, but it only works on one file at a time.
adrian
Posts: 2453

Re: Inserting a block of text into every record

Fri Aug 23, 2013 12:53 pm

Hi,

What XPath expression did you use?
How is the XML document structured?

If the XPath results don't match anything then the search won't be able to find anything.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
radu_pisoi
Posts: 328
Location: Craiova

Re: Inserting a block of text into every record

Tue Jun 23, 2015 8:58 am

akyrios wrote:Another entry in the "this may be really obvious" series. I have a block of text for contact information metadata that I'd like to insert in each of several thousand records. I can't use a simple copy and paste, because I want to put the block after an element that appears more than once in each record (and I only want the block once in each). Is there a simple insert function that could help me do this?


I just wanted to let you know that the latest version (v17.0) of Oxygen contains the XML Refactoring tool that assists you with various refactoring tasks.

It helps you manage the structure of your XML documents and it includes a variety of operations, such as renaming, deleting, and inserting elements and attributes across a set of files. It is available in the Tools menu, the Project and DITA Maps Manager contextual menu.

In your case, you could use the 'Insert XML fragment' operation to insert a text fragment in a certain document position.

You can read more details about this feature in our documentation:
http://www.oxygenxml.com/doc/versions/1 ... ments.html
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 3 guests