Processing oxy_delete processing instruction

Here should go questions about transforming XML with XSLT and FOP.
tmakita
Posts: 100
Joined: Fri Apr 08, 2011 7:58 am

Processing oxy_delete processing instruction

Post by tmakita »

Hi,

I want to use oxy_delete processing instruction with my XSLT stylesheet.

[Source Document]

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="topic_v5d_3ly_hn">
<title>Change tracking example</title>
<body>
<p>Mr. Abe's TPP<?oxy_delete author="toshi" timestamp="20140321T225157+0900" content="<term keyref="KAIKOKU_OPEN"/>"?>
<?oxy_insert_start author="toshi" timestamp="20140321T225137+0900"?><term
keyref="KAIKOKU_BREAK"/><?oxy_insert_end?></p>
</body>
</topic>
<?oxy_options track_changes="on"?>
[Stylesheet]

Code: Select all

    <xsl:template match="processing-instruction('oxy_delete')" priority="2">
<xsl:variable name="piText" as="xs:string" select="string(.)"/>
<xsl:variable name="regX" as="xs:string" select="'author="(.+)" timestamp="(.+)" content="(.+)"'"/>
<xsl:variable name="author" as="xs:string" select="replace($piText,$regX,'$1')"/>
<xsl:variable name="timeStamp" as="xs:string" select="replace($piText,$regX,'$2')"/>
<xsl:variable name="content" as="xs:string" select="replace($piText,$regX,'$3')"/>
<xsl:message select="'author=',$author"/>
<xsl:message select="'timestamp=',$timeStamp"/>
<xsl:message select="'content=',$content"/>
</xsl:template>
This template outputs following message:

Description: [Saxon-PE] author= toshi
Description: [Saxon-PE] timestamp= 20140321T225157+0900
Description: [Saxon-PE] content= &lt;term keyref=&quot;KAIKOKU_OPEN&quot;/&gt;

As you can see, '<' , '>' and '"' are doubly escaped in $content.

Are there any ways to restore $content into XML fragment using XSLT stylesheet? I want parse it using parse-xml-fragment() function.

Regards,

Toshihiko Makita
--
/*--------------------------------------------------
Toshihiko Makita
Development Group. Antenna House, Inc. Ina Branch
Web site:
http://www.antenna.co.jp/
http://www.antennahouse.com/
--------------------------------------------------*/
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: Processing oxy_delete processing instruction

Post by Radu »

Hi Toshihiko,

My colleague George created such a stylesheet a while ago, I'm attaching it below:

Code: Select all

<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">
<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>
It uses XSLT 2.0 and the Saxon 9 specific extension "saxon:parse" (it is used twice to remove that double escaping you noticed):

http://www.saxonica.com/documentation9. ... parse.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
tmakita
Posts: 100
Joined: Fri Apr 08, 2011 7:58 am

Re: Processing oxy_delete processing instruction

Post by tmakita »

Hi Radu,
(it is used twice to remove that double escaping you noticed):
Nice suggestion :D
Thank you!

Regards,

Toshihiko Makita
--
/*--------------------------------------------------
Toshihiko Makita
Development Group. Antenna House, Inc. Ina Branch
Web site:
http://www.antenna.co.jp/
http://www.antennahouse.com/
--------------------------------------------------*/
Post Reply