Remove wrapping p tag in table entries

Questions about XML that are not covered by the other forums should go here.
kirkilj
Posts: 61

Remove wrapping p tag in table entries

Fri Feb 12, 2016 8:33 pm

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
kirkilj
Posts: 61

Re: Remove wrapping p tag in table entries

Mon Feb 15, 2016 10:53 pm

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.
radu_pisoi
Posts: 318
Location: Craiova

Re: Remove wrapping p tag in table entries

Tue Feb 16, 2016 10:55 am

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'.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
kirkilj
Posts: 61

Re: Remove wrapping p tag in table entries

Tue Feb 16, 2016 9:01 pm

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

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest