Page 1 of 1

Rendering oxy_delete Processing Instructions

Posted: Thu May 10, 2012 6:23 pm
by bpopp
This isn't exactly an OxygenXML issue, but I'm hoping someone can help me. Basically I'm trying to render the content attribute of the Oxygen delete processing instruction to PDF. My ultimate objective is to render deleted content with strikethru styling. Here's the rule I'm trying:

Code: Select all


<xsl:variable name="contents"><xsl:value-of disable-output-escaping="yes" select="substring-before(substring-after(.,'content="'), '"')"/></xsl:variable>

<xsl:for-each select="exslt:node-set($contents)">
<xsl:apply-templates select="." mode="deleted"/>
</xsl:for-each>
And then I wrote a set of templates to match the nodes:

Code: Select all


<xsl:template match="p" mode="deleted"  >
<xsl:message>delete::para hit</xsl:message>
<fo:inline color="blue" text-decoration="line-through">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<xsl:template match="text()" mode="deleted" >
<xsl:message>delete::text() hit</xsl:message>
<fo:inline color="red" text-decoration="line-through">
<xsl:value-of select="."/>
</fo:inline>
</xsl:template>
This "almost" works, but the exslt:node-set($contents) is interpretting all the encoded markup as a single string. I can't figure out a good way to decode the < and > markup before it gets to that function so that node-set will interpret it as a set of matchable nodes instead of a single string.I had hoped the disable-output-escaping would do it, but no luck.

Any tips or suggestions are very appreciated. Thanks.

Brian

Re: Rendering oxy_delete Processing Instructions

Posted: Mon May 14, 2012 11:38 am
by george
Hi Brian,

I sent you a reply already on the dita-users list. Here it is again that stylesheet that converts the delete PIs to XML elements. You may change that to covert to whatever markup you need.
Please make sure you set Saxon 9 PE or EE as your XSLT processor.

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xd saxon"
version="2.0">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Feb 11, 2011</xd:p>
<xd:p><xd:b>Author:</xd:b> george</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>
<xsl:template match="processing-instruction()[name()='oxy_delete']">
<xsl:variable name="c" select="substring-after(., 'content=')"/>
<xsl:variable name="clen" select="string-length($c) - 2"/>
<xsl:variable name="content">
<xsl:text><tmp></xsl:text>
<xsl:value-of select="substring($c, 2 , $clen)"/>
<xsl:text></tmp></xsl:text>
</xsl:variable>
<xsl:variable name="xmlContent">
<xsl:text><deleted </xsl:text>
<xsl:value-of select="substring-before(.,
'content=')"></xsl:value-of>
<xsl:text>></xsl:text>
<xsl:value-of select="saxon:parse($content)"/>
<xsl:text></deleted></xsl:text>
</xsl:variable>
<xsl:element name="trackchange">
<xsl:attribute name="revisionflag">deleted</xsl:attribute>
<xsl:copy-of select="saxon:parse($xmlContent)/*/node()"/>
</xsl:element>
</xsl:template>

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Re: Rendering oxy_delete Processing Instructions

Posted: Wed May 16, 2012 5:34 am
by bpopp
george wrote:Hi Brian,

I sent you a reply already on the dita-users list. Here it is again that stylesheet that converts the delete PIs to XML elements. You may change that to covert to whatever markup you need.
Please make sure you set Saxon 9 PE or EE as your XSLT processor.
Thanks so much. I look forward to trying this in the morning.

Brian

Re: Rendering oxy_delete Processing Instructions

Posted: Thu May 17, 2012 2:00 am
by bpopp
George's solution above partially worked, but it still left the content encoded so that in my rendered output I was getting:

Code: Select all

<p>Here's a deleted paragraph</p>
To fix this, the solution I finally came up with was to do a simple search and replace on the tag encoding and replace them with < and > symbols like so:

Code: Select all

<xsl:template name="escape">
<xsl:param name="text"/>
<xsl:value-of select="replace(replace($text,'&gt;','>'),'&lt;','<')"/>
</xsl:template>
And then the code to handle the processing instruction looks like:

Code: Select all

   <xsl:template match="processing-instruction('oxy_delete')">
<xsl:variable name="c" select="substring-after(.,'content=')" />
<xsl:variable name="clen" select="string-length($c) - 2" />

<xsl:variable name="content">
<xsl:text><tmp></xsl:text>

<xsl:call-template name="escape">
<xsl:with-param name="text" select="substring($c,2,$clen)"></xsl:with-param>
</xsl:call-template>

<xsl:text></tmp></xsl:text>
</xsl:variable>



<fo:change-bar-begin change-bar-class="C20040405-4" change-bar-style="solid"
change-bar-color="black" change-bar-offset="2mm" change-bar-placement="end" />

<xsl:apply-templates mode="deleted" select="saxon:parse($content)" />
<fo:change-bar-end change-bar-class="C20040405-4" />




</xsl:template>
I had tried this originally and it didn't work so I suspect saxon's parsing is doing a better job than my original parser (exslt:node). Thanks so much to George for pointing me in the right direction.

Here's the final output:
Image