| 1 | <?xml version="1.0" encoding="UTF-8" ?> |
|---|
| 2 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|---|
| 3 | xmlns:dfx="http://www.topologi.org/2004/Diff-X" |
|---|
| 4 | xmlns:del="http://www.topologi.org/2004/Diff-X/Delete" |
|---|
| 5 | xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" |
|---|
| 6 | xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" |
|---|
| 7 | xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" |
|---|
| 8 | xmlns:o="urn:schemas-microsoft-com:office:office" |
|---|
| 9 | xmlns:v="urn:schemas-microsoft-com:vml" |
|---|
| 10 | xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint" |
|---|
| 11 | xmlns:aml="http://schemas.microsoft.com/aml/2001/core" |
|---|
| 12 | xmlns:w10="urn:schemas-microsoft-com:office:word" |
|---|
| 13 | xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage" |
|---|
| 14 | xmlns:msxsl="urn:schemas-microsoft-com:xslt" |
|---|
| 15 | xmlns:ext="http://www.xmllab.net/wordml2html/ext" |
|---|
| 16 | xmlns:java="http://xml.apache.org/xalan/java" |
|---|
| 17 | xmlns:xml="http://www.w3.org/XML/1998/namespace" |
|---|
| 18 | version="1.0" |
|---|
| 19 | exclude-result-prefixes="java msxsl ext o v WX aml w10"> |
|---|
| 20 | |
|---|
| 21 | <!-- |
|---|
| 22 | * Copyright 2007, Plutext Pty Ltd. |
|---|
| 23 | * |
|---|
| 24 | * This file is part of plutext-client-word2007. |
|---|
| 25 | |
|---|
| 26 | plutext-client-word2007 is free software: you can redistribute it and/or |
|---|
| 27 | modify it under the terms of version 3 of the GNU General Public License |
|---|
| 28 | as published by the Free Software Foundation. |
|---|
| 29 | |
|---|
| 30 | plutext-client-word2007 is distributed in the hope that it will be |
|---|
| 31 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
|---|
| 32 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 33 | GNU General Public License for more details. |
|---|
| 34 | |
|---|
| 35 | You should have received a copy of the GNU General Public License |
|---|
| 36 | along with plutext-client-word2007. If not, see |
|---|
| 37 | <http://www.gnu.org/licenses/>. |
|---|
| 38 | |
|---|
| 39 | --> |
|---|
| 40 | |
|---|
| 41 | <xsl:param name="Differencer"/> |
|---|
| 42 | <xsl:param name="author"/> |
|---|
| 43 | <xsl:param name="date"/> |
|---|
| 44 | <xsl:param name="docPartRelsLeft"/> |
|---|
| 45 | <xsl:param name="docPartRelsRight"/> |
|---|
| 46 | <xsl:param name="relsDiffIdentifier"/> |
|---|
| 47 | |
|---|
| 48 | <xsl:preserve-space elements="w:t"/> |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" /> |
|---|
| 52 | |
|---|
| 53 | <xsl:template match="/ | @*|node()"> |
|---|
| 54 | <xsl:copy> |
|---|
| 55 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 56 | </xsl:copy> |
|---|
| 57 | </xsl:template> |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | <xsl:template match="w:r"> |
|---|
| 61 | |
|---|
| 62 | <xsl:variable name="id" |
|---|
| 63 | select="java:org.docx4j.diff.Differencer.getId()" /> |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | <w:ins w:id="{$id}" w:author="{$author}" w:date="{$date}"> <!-- w:date is optional --> |
|---|
| 67 | <xsl:apply-templates/> |
|---|
| 68 | </w:ins> |
|---|
| 69 | |
|---|
| 70 | </xsl:template> |
|---|
| 71 | |
|---|
| 72 | <xsl:template match="w:t"> |
|---|
| 73 | |
|---|
| 74 | <xsl:apply-templates/> |
|---|
| 75 | |
|---|
| 76 | </xsl:template> |
|---|
| 77 | |
|---|
| 78 | <!-- Handle <w:sym w:font="Wingdings" w:char="F04A" /> --> |
|---|
| 79 | <xsl:template match="w:sym"> |
|---|
| 80 | <w:r> |
|---|
| 81 | <xsl:apply-templates select="../../w:rPr" mode="omitDeletions"/> |
|---|
| 82 | <xsl:copy> |
|---|
| 83 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 84 | </xsl:copy> |
|---|
| 85 | </w:r> |
|---|
| 86 | </xsl:template> |
|---|
| 87 | |
|---|
| 88 | <xsl:template match="w:sectPr"> |
|---|
| 89 | <xsl:copy> |
|---|
| 90 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 91 | </xsl:copy> |
|---|
| 92 | </xsl:template> |
|---|
| 93 | |
|---|
| 94 | <!-- Drop these. |
|---|
| 95 | If you want them, you'll need to attend to their r:id, using |
|---|
| 96 | java:org.docx4j.diff.Differencer.registerRelationship |
|---|
| 97 | (see example below) --> |
|---|
| 98 | <xsl:template match="w:headerReference" /> |
|---|
| 99 | <xsl:template match="w:footerReference" /> |
|---|
| 100 | |
|---|
| 101 | <!-- w:drawing: there are 3 cases: |
|---|
| 102 | |
|---|
| 103 | (1) drawing deleted (ie present in RHS only) NOT RELEVANT TO MarkupInsert |
|---|
| 104 | (2) drawing, inserted in LHS |
|---|
| 105 | |
|---|
| 106 | (3) normal drawing, present in LHS & RHS |
|---|
| 107 | |
|---|
| 108 | --> |
|---|
| 109 | |
|---|
| 110 | <xsl:template match="w:drawing" priority="3"> |
|---|
| 111 | |
|---|
| 112 | <xsl:choose> |
|---|
| 113 | <xsl:when test="@dfx:delete='true'"> <!-- NOT RELEVANT TO MarkupInsert --> |
|---|
| 114 | <xsl:variable name="id" |
|---|
| 115 | select="java:org.docx4j.diff.Differencer.getId()" /> |
|---|
| 116 | <w:del w:id="{$id}" w:author="{$author}" w:date="{$date}"> <!-- w:date is optional --> |
|---|
| 117 | <w:r> |
|---|
| 118 | <xsl:copy> |
|---|
| 119 | <xsl:apply-templates select="node()"/> <!-- drop @ --> |
|---|
| 120 | </xsl:copy> |
|---|
| 121 | </w:r> |
|---|
| 122 | </w:del> |
|---|
| 123 | </xsl:when> |
|---|
| 124 | <xsl:when test="@dfx:insert='true'"> |
|---|
| 125 | <xsl:variable name="id" |
|---|
| 126 | select="java:org.docx4j.diff.Differencer.getId()" /> |
|---|
| 127 | <w:ins w:id="{$id}" w:author="{$author}" w:date="{$date}"> <!-- w:date is optional --> |
|---|
| 128 | <w:r> |
|---|
| 129 | <xsl:copy> |
|---|
| 130 | <xsl:apply-templates select="node()"/> <!-- drop @ --> |
|---|
| 131 | </xsl:copy> |
|---|
| 132 | </w:r> |
|---|
| 133 | </w:ins> |
|---|
| 134 | </xsl:when> |
|---|
| 135 | <xsl:otherwise> |
|---|
| 136 | <w:r> |
|---|
| 137 | <xsl:copy> |
|---|
| 138 | <xsl:apply-templates select="node()"/> <!-- drop @, though there shouldn't be any --> |
|---|
| 139 | </xsl:copy> |
|---|
| 140 | </w:r> |
|---|
| 141 | </xsl:otherwise> |
|---|
| 142 | </xsl:choose> |
|---|
| 143 | |
|---|
| 144 | </xsl:template> |
|---|
| 145 | |
|---|
| 146 | <xsl:template match="a:blip" priority="5"> |
|---|
| 147 | |
|---|
| 148 | <xsl:choose> |
|---|
| 149 | <!-- case (1) drawing deleted (ie present in RHS only) |
|---|
| 150 | IRRELEVANT HERE --> |
|---|
| 151 | <xsl:when test="@dfx:delete='true'"> |
|---|
| 152 | <!-- Handle link|embed --> |
|---|
| 153 | <xsl:choose> |
|---|
| 154 | <xsl:when test="count(@del:link)=1"> |
|---|
| 155 | <xsl:variable name="oldid" select="string(@del:link)" /> |
|---|
| 156 | <xsl:variable name="newid" select="concat($oldid, 'R', $relsDiffIdentifier)" /> <!-- From RIGHT rels --> |
|---|
| 157 | <xsl:variable name="dummy" |
|---|
| 158 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 159 | $Differencer, $docPartRelsRight, $oldid, $newid)" /> |
|---|
| 160 | <a:blip r:link="{$newid}" /> |
|---|
| 161 | </xsl:when> |
|---|
| 162 | <xsl:otherwise> <!-- r:embed --> |
|---|
| 163 | <xsl:variable name="oldid" select="string(@del:embed)" /> |
|---|
| 164 | <xsl:variable name="newid" select="concat($oldid, 'R', $relsDiffIdentifier)" /> <!-- From RIGHT rels --> |
|---|
| 165 | <xsl:variable name="dummy" |
|---|
| 166 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 167 | $Differencer, $docPartRelsRight, $oldid, $newid)" /> |
|---|
| 168 | <a:blip r:embed="{$newid}" /> |
|---|
| 169 | </xsl:otherwise> |
|---|
| 170 | </xsl:choose> |
|---|
| 171 | </xsl:when> |
|---|
| 172 | <!-- cases: |
|---|
| 173 | (2) drawing, inserted in LHS |
|---|
| 174 | (3) normal drawing, present in LHS & RHS |
|---|
| 175 | --> |
|---|
| 176 | <xsl:otherwise> |
|---|
| 177 | <!-- Handle link|embed --> |
|---|
| 178 | <xsl:choose> |
|---|
| 179 | <xsl:when test="count(@r:link)=1"> |
|---|
| 180 | <xsl:variable name="oldid" select="string(@r:link)" /> |
|---|
| 181 | <xsl:variable name="newid" select="concat($oldid, 'L', $relsDiffIdentifier)" /> <!-- LEFT --> |
|---|
| 182 | <xsl:variable name="dummy" |
|---|
| 183 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 184 | $Differencer, $docPartRelsLeft, $oldid, $newid)" /> |
|---|
| 185 | <a:blip r:link="{$newid}" /> |
|---|
| 186 | </xsl:when> |
|---|
| 187 | <xsl:otherwise> <!-- r:embed --> |
|---|
| 188 | <xsl:variable name="oldid" select="string(@r:embed)" /> |
|---|
| 189 | <xsl:variable name="newid" select="concat($oldid, 'L', $relsDiffIdentifier)" /> <!-- LEFT --> |
|---|
| 190 | <xsl:variable name="dummy" |
|---|
| 191 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 192 | $Differencer, $docPartRelsLeft, $oldid, $newid)" /> |
|---|
| 193 | <a:blip r:embed="{$newid}" /> |
|---|
| 194 | </xsl:otherwise> |
|---|
| 195 | </xsl:choose> |
|---|
| 196 | </xsl:otherwise> |
|---|
| 197 | </xsl:choose> |
|---|
| 198 | |
|---|
| 199 | </xsl:template> |
|---|
| 200 | |
|---|
| 201 | <!-- Recover deleted drawing; not relevant to MarkupInsert. |
|---|
| 202 | |
|---|
| 203 | <xsl:template match="@dfx:delete[ancestor::w:drawing]" /> |
|---|
| 204 | |
|---|
| 205 | <xsl:template match="@del:*[ancestor::w:drawing]" > |
|---|
| 206 | <xsl:attribute name="{local-name(.)}"> |
|---|
| 207 | <xsl:value-of select="." /> |
|---|
| 208 | </xsl:attribute> |
|---|
| 209 | </xsl:template> |
|---|
| 210 | --> |
|---|
| 211 | |
|---|
| 212 | <!-- Fix inserted drawing? No, nothing to do here, since @dfx:insert="true" |
|---|
| 213 | is removed above. |
|---|
| 214 | |
|---|
| 215 | <w:r dfx:insert="true"><w:rPr dfx:insert="true"><w:noProof dfx:insert="true" /> |
|---|
| 216 | </w:rPr> |
|---|
| 217 | <w:drawing dfx:insert="true"> |
|---|
| 218 | <wp:inline dfx:insert="true"> |
|---|
| 219 | <wp:extent dfx:insert="true" cx="457200" cy="400050" /> |
|---|
| 220 | |
|---|
| 221 | --> |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | <!-- w:hyperlink @r:id |
|---|
| 225 | |
|---|
| 226 | <w:hyperlink dfx:insert="true" r:id="rId5" w:history="true"> |
|---|
| 227 | <w:r> |
|---|
| 228 | <w:rPr dfx:insert="true"><w:rStyle dfx:insert="true" w:val="Hyperlink" /></w:rPr> |
|---|
| 229 | <w:t> |
|---|
| 230 | <ins>http://slashdot.org</ins> |
|---|
| 231 | <del>3</del> |
|---|
| 232 | </w:t> |
|---|
| 233 | </w:r> |
|---|
| 234 | </w:hyperlink> |
|---|
| 235 | |
|---|
| 236 | Word 2007 tracks the insertion/deletion of hyperlinks using |
|---|
| 237 | w:ins and w:del around the corresponding fields. |
|---|
| 238 | |
|---|
| 239 | We could replicate that, I guess. |
|---|
| 240 | |
|---|
| 241 | But for now, *we don't track the hyperlink itself*; just the text inside it. |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | --> |
|---|
| 245 | <xsl:template match="w:hyperlink" priority="5"> |
|---|
| 246 | |
|---|
| 247 | <xsl:choose> |
|---|
| 248 | <xsl:when test="@dfx:delete='true'"> |
|---|
| 249 | <xsl:variable name="id" |
|---|
| 250 | select="java:org.docx4j.diff.Differencer.getId()" /> |
|---|
| 251 | |
|---|
| 252 | <xsl:variable name="oldid" select="string(@del:id)" /> |
|---|
| 253 | <xsl:variable name="newid" select="concat($oldid, 'R', $relsDiffIdentifier)" /> <!-- From RIGHT rels --> |
|---|
| 254 | <xsl:variable name="dummy" |
|---|
| 255 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 256 | $Differencer, $docPartRelsRight, $oldid, $newid)" /> |
|---|
| 257 | <w:hyperlink r:id="{$newid}"> |
|---|
| 258 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 259 | </w:hyperlink> |
|---|
| 260 | </xsl:when> |
|---|
| 261 | <xsl:when test="@dfx:insert='true'"> |
|---|
| 262 | <xsl:variable name="id" |
|---|
| 263 | select="java:org.docx4j.diff.Differencer.getId()" /> |
|---|
| 264 | <xsl:variable name="oldid" select="string(@r:id)" /> |
|---|
| 265 | <xsl:variable name="newid" select="concat($oldid, 'L', $relsDiffIdentifier)" /> <!-- LEFT --> |
|---|
| 266 | <xsl:variable name="dummy" |
|---|
| 267 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 268 | $Differencer, $docPartRelsLeft, $oldid, $newid)" /> |
|---|
| 269 | <w:hyperlink r:id="{$newid}"> |
|---|
| 270 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 271 | </w:hyperlink> |
|---|
| 272 | </xsl:when> |
|---|
| 273 | <xsl:otherwise> |
|---|
| 274 | <xsl:variable name="oldid" select="string(@r:id)" /> |
|---|
| 275 | <xsl:variable name="newid" select="concat($oldid, 'L', $relsDiffIdentifier)" /> <!-- LEFT --> |
|---|
| 276 | <xsl:variable name="dummy" |
|---|
| 277 | select="java:org.docx4j.diff.Differencer.registerRelationship( |
|---|
| 278 | $Differencer, $docPartRelsLeft, $oldid, $newid)" /> |
|---|
| 279 | <w:hyperlink r:id="{$newid}"> |
|---|
| 280 | <xsl:apply-templates select="@*|node()"/> |
|---|
| 281 | </w:hyperlink> |
|---|
| 282 | </xsl:otherwise> |
|---|
| 283 | </xsl:choose> |
|---|
| 284 | |
|---|
| 285 | </xsl:template> |
|---|
| 286 | |
|---|
| 287 | <!-- |
|---|
| 288 | TODO |
|---|
| 289 | w:object/v:imagedata |
|---|
| 290 | |
|---|
| 291 | w:object/o:OLEObject |
|---|
| 292 | |
|---|
| 293 | --> |
|---|
| 294 | |
|---|
| 295 | <!-- comments, footnotes, endnotes are simply stripped. |
|---|
| 296 | Handling these properly requires composing new parts, |
|---|
| 297 | for which an extension function similar to |
|---|
| 298 | registerRelationship would be required. |
|---|
| 299 | |
|---|
| 300 | Quite feasible, but a TODO. --> |
|---|
| 301 | <xsl:template match="w:commentReference | w:commentRangeStart | w:commentRangeEnd" /> |
|---|
| 302 | |
|---|
| 303 | <xsl:template match="w:footnoteReference | w:endnoteReference" /> |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | <xsl:template match="w:tab[parent::w:r]"> <!-- so we don't match tab in properties --> |
|---|
| 308 | |
|---|
| 309 | <w:r> |
|---|
| 310 | <xsl:apply-templates select="../w:rPr" /> |
|---|
| 311 | <w:tab/> |
|---|
| 312 | </w:r> |
|---|
| 313 | |
|---|
| 314 | </xsl:template> |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | <xsl:template match="text()"> |
|---|
| 318 | |
|---|
| 319 | <w:r> |
|---|
| 320 | <xsl:apply-templates select="../../w:rPr"/> |
|---|
| 321 | <w:t xml:space="preserve"><xsl:value-of select="."/></w:t> |
|---|
| 322 | </w:r> |
|---|
| 323 | |
|---|
| 324 | </xsl:template> |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | </xsl:stylesheet> |
|---|
| 329 | |
|---|