Page 1 of 1

Remove wrapping p tag in table entries

Posted: Fri Feb 12, 2016 8:33 pm
by kirkilj
Greetings,

I'm dusting off my XPath skills and have forgotten more than I thought. I've done many searches, but have yet to divine an answer. In XSLT, I need to find all cells with a particular type of table and have their entire contents wrapped in a single paragraph element with nothing before or after that tag, and strip out the wrapping p element. I can select the cells I'm after that having only one p tag using the following XPath in Oxygen's XPath debugger:

//table[contains(@outputclass,'BitFieldTable')]//entry[@colname='Description'][count(p) = 1]

However, this p element can be anywhere, and I want to insure that there are no other tags or text nodes before or after it. The DITA in question is generated by upstream processes that have used different DITA generation logic with successive versions of the generator. DeltaXML is seeing these as false positive differences, and I'm creating an XSLT in the pipeline to normalize generator differences before the diff takes place.

As a side question, when I copy the above XPath expression into the XWatch view, nothing appears in the value column. Do the expressions in XWatch only evaluate in the context of running an XSLT stylesheet in the debugger? If so, would creating an identity transform be sufficient?

John

Re: Remove wrapping p tag in table entries

Posted: Mon Feb 15, 2016 10:53 pm
by kirkilj
Update: I'm able to locate the table cells I want with:

Code: Select all

//table[contains(@outputclass,'BitFieldTable')]//entry[@colname='Description'][count(p) = 1 and count(p/*) = 0  and count(node()) = 1]
which will find the table cells I'm looking for, such as:

Code: Select all

<entry colname="Description"><p>Captures xyz signals</p></entry>
or
<entry colname="Description"><p></p></entry>
Now I just need to unwrap and omit the paragraph tag in the output. There's a lot of implicit stuff going on in XSLT and XPath, which is great, once a critical mass of understanding is achieved.

Re: Remove wrapping p tag in table entries

Posted: Tue Feb 16, 2016 10:55 am
by radu_pisoi
Hi,
kirkilj wrote:Now I just need to unwrap and omit the paragraph tag in the output. There's a lot of implicit stuff going on in XSLT and XPath, which is great, once a critical mass of understanding is achieved.
In this case, a solution is to use the XML Refactoring tool that was designed for modifying the structure of a collection of XML documents.
Some of the advantages of the XML Refactoring tool over a normal XSLT transformation are:
* the DOCTYPE declaration is preserved;
* the entities are not expanded;
* the default attributes are not added;

You can find additional information about XML Refactoring tool in our documentation, http://oxygenxml.com/doc/versions/17.1/ ... ments.html

Now, regarding your request, to unwrap the paragraph tag in the output:
* open the XML Refactoring dialog from the Tools menu;
* select the Unwrap operation;
* specify the XPath that selects the elements you want to unwrap;
* specify the operation scope, files affected by the operation. If you are working with DITA, you can simply select the 'Current DITA map hierarchy'.

Re: Remove wrapping p tag in table entries

Posted: Tue Feb 16, 2016 9:01 pm
by kirkilj
Hello Radu,

I did not provide one critical piece of context. This transformation is going to run as part of a batch process. I'm using Oxygen as an XSLT development and debugging tool, and the use of the Refactor functionality is not an option.

John