XSL Transformation Assistance Needed



I am trying to transform an xml file to another xml file using XSL 1.0.


The source file contains unwanted emphasis elements that I need to drop in the output. In the following example, you will see <emphasis> are used to describe text that occurs within a <p>. In the first instance, <emphasis type="i"> contains another <emphasis type="i">. In the second instance the <emphasis type="i"> contains an <emphasis> that contains another <emphasis type="i">.



<!-- 1st instance --><para>Text text text text text <emphasis type="i">italicized text
<emphasis type="i">more italicized text</emphasis>, text text text text text text</emphasis>.
Text text text text text<!-- 2nd instance --><emphasis type="i"><emphasis>
<emphasis type="i">italicized text</emphasis>, text text text text text </emphasis> text text
text text text text</emphasis> text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text
text text text .</p>


In the first instance, I need to keep the wrapper, strip the second <emphasis type="i"> and keep the text so that it appears as so:


<p>Text text text text text <emphasis type="i">italicized text more italicized text, text text text text text text</emphasis>


In the second instance, I need to keep the wrapper <emphasis type="i"> but strip the <emphasis> and the next <emphasis type="i"> so that it appears as so:



<emphasis type="i">italicized text, text text text text text text text text text text
text</emphasis> text text text text text text text text text text text text text text text
text text text text text text text text text text text text text text text text text text text
text .</p>


I have tried matching emphasis and choosing when @type ='i' and when Child::emphasis [type='i']


I have tried matching emphasis/emphasis and choosing when @type='i'


I have tried matching p and using for-each select emphasis/emphasis[type='i'] and outputting value of select .


I have tried matching p and for-each select emphasis[type='i']/emphasis/emphasis[type='i']


I don't know how to output the text without the unwanted <emphasis>. I can submit the code i used if that would be helpful, but I really doubt it will do anyone any good :)


I would sincerely appreciate any assistance anyone can offer.


In addition to the italic attribute, this same scenario could occur for bold, underline caps and quotes. In all instances I need to find the attribute type of the wrapper <emphasis> and if the nested <emphasis> contain the same attribute, I need to remove them. The nested, unwanted <emphasis> are causing havoc in my publishing system.


No comments:

Post a Comment