Convert <br /> elements to <p /> during html copy

Questions about XML that are not covered by the other forums should go here.
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

Convert <br /> elements to <p /> during html copy

Post by eloralon »

Hello,

Is it possible to convert <br/> from legacy html to <p/> during copy and paste process?

I have some content from html, which I usually copy from the browser to oXygen in Author mode for further cleaning.

Hopefully there is a way to convert these <br/> elements to <p/> elements because I have a good number of them.

Thanks
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Convert <br /> elements to <p /> during html copy

Post by sorin_ristache »

Hello,

The paste operation executed in Author mode just tries to transform the markup of the source HTML document to an equivalent one in the target document, that is a list/table/image/link/etc. will remain a list/table/image/link/etc. in the language of the target document (XHTML, DITA, DocBook, TEI). The paste operation does not transform a <br/> element to a <p/> one. I suggest creating and running an XSLT stylesheet on the XML document for adding the <p/> elements that will replace the <br/> ones.


Regards,
Sorin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Convert <br /> elements to <p /> during html copy

Post by sorin_ristache »

eloralon wrote:I have some content from html, which I usually copy from the browser to oXygen in Author mode for further cleaning.

Hopefully there is a way to convert these <br/> elements to <p/> elements because I have a good number of them.
If you paste in Author mode in a DITA topic file, a DocBook document, a TEI document or an XHTML one you can convert all <br/> elements to <p/> elements by modifying the XSLT stylesheet that does the conversion of the copied fragment:
  • for DITA topics the XSLT stylesheet is [Oxygen-folder]\frameworks\dita\resources\xhtml2dita.xsl
  • for DocBook 4 the XSLT stylesheet is [Oxygen-folder]\frameworks\docbook\resources\xhtml2db4.xsl
  • for DocBook 5 the XSLT stylesheet is [Oxygen-folder]\frameworks\docbook\resources\xhtml2db5.xsl
  • for TEI 4 the XSLT stylesheet is [Oxygen-folder]\frameworks\tei\resources\xhtml2tei4.xsl
  • for TEI 5 the XSLT stylesheet is [Oxygen-folder]\frameworks\tei\resources\xhtml2tei5.xsl
  • for XHTML the XSLT stylesheet is [Oxygen-folder]\frameworks\xhtml\resources\xhtml2xhtml.xsl

Regards,
Sorin
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

Re: Convert <br /> elements to <p /> during html copy

Post by eloralon »

Thanks Sorin for your reply,

Since I have a very rudimentary understanding of xslt because I am still learning it. Would you please tell me how to go about the change for the <br/> conversion to <p/>?

Looking through the xslt style sheet for html to DITA I saw the following template:

Code: Select all

 <xsl:template match="xhtml:p">
<xsl:choose>
<xsl:when test="not(parent::xhtml:th | parent::xhtml:td) and not(normalize-space(.) = '')">
<p>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="." mode="checkHeadings"/>
</p>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="." mode="checkHeadings"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
, which I think needs to be copied and modified for my purpose. Trouble is that I don't really know how to?

Thanks.

Loralon
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Convert <br /> elements to <p /> during html copy

Post by sorin_ristache »

Hello,

Please look at some XSLT tutorials. Maybe some XSLT experts from the XSL-List mailing list can be more helpful.


Regards,
Sorin
Post Reply