XSLTを使用してdocxを解析する方法

docx形式のドキュメント、xlsxテーブル、pptxプレゼンテーションを処理するタスクは非常に簡単です。 この記事では、XSLTとZIPアーカイバーのみを使用して、そのようなドキュメントを解析、作成、処理する方法を学ぶ方法を説明します。







なんで?



docxは最も一般的なドキュメント形式であるため、この形式でユーザーに情報を提供するタスクは常に発生します。 この問題の解決策の1つ-既製のライブラリを使用することは、いくつかの理由で適切ではない場合があります。









したがって、この記事では、docxドキュメントを操作するための最も基本的なツールのみを使用します。







Docx構造



最初に、docxドキュメントとは何かを理解しましょう。 docxは、2種類のファイルを物理的に含むzipアーカイブです。









そして論理的に-3種類の要素:









それらは、 ECMA-376規格で詳しく説明されています。OfficeOpen XML File Formatsの主要部分は5000ページのPDF文書であり、さらに2000ページのボーナスコンテンツです。







最小docx



解凍後の最も簡単なdocxは次のとおりです。







画像







それが何で構成されるかをてみましょう。







[Content_Types] .xml



ドキュメントのルートにあり、ドキュメントコンテンツのMIMEタイプをリストします。







 <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/> <Default Extension="xml" ContentType="application/xml"/> <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/> </Types>
      
      





_rels / .rels



ドキュメントリンクのメインリスト。 この場合、定義される関係は1つだけです(識別子rId1とword / document.xmlファイルとの比較)-ドキュメントの本文。







 <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/> </Relationships>
      
      





word / document.xml



ドキュメントのメインコンテンツ







word / document.xml
 <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 wp14"> <w:body> <w:pw:rsidR="005F670F" w:rsidRDefault="005F79F5"> <w:r> <w:t>Test</w:t> </w:r> <w:bookmarkStart w:id="0" w:name="_GoBack"/> <w:bookmarkEnd w:id="0"/> </w:p> <w:sectPr w:rsidR="005F670F"> <w:pgSz w:w="12240" w:h="15840"/> <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/> <w:cols w:space="720"/> <w:docGrid w:linePitch="360"/> </w:sectPr> </w:body> </w:document>
      
      





ここに:









このドキュメントをテキストエディタで開くと、1つの単語Test



からドキュメントが表示されます。







word / _rels / document.xml.rels



以下はword/document.xml



へのリンクのリストです。 リンクファイルの名前は、関連するドキュメントの一部の名前と、 rels



拡張の追加から作成されます。 リンクファイルのあるフォルダーは_rels



と呼ばれ、関連する部分と同じレベルにあります。 word/document.xml



リンクがないためword/document.xml



ファイルは空です。







 <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> </Relationships>
      
      





リンクがない場合でも、このファイルが存在している必要があります。







docxおよびMicrosoft Word



docxはMicrosoft Wordを使用して作成されましたが、原則として、他のエディターの助けを借りて、 いくつかの追加ファイルがあります







画像







含まれるものは次のとおりです。









複雑なドキュメントでは、パーツがさらに大きくなる可能性があります。







リバースエンジニアリングdocx



そのため、最初のタスクは、ドキュメントのフラグメントがxmlにどのように保存されているかを調べ、そのようなドキュメントを自分で作成(または解析)することです。 これには次のものが必要です。









ツール





また、XMLを自動的に(一度)アーカイブおよびフォーマットするためのスクリプトが必要になります。

Windowsで使用:









Linuxでの使用も同様で、 unpack



ではなく./unpack.sh



のみで、 pack



./pack.sh



なり./pack.sh









使用する



変更の検索は次のとおりです。







  1. エディターで空のdocxファイルを作成します。
  2. unpack



    して新しいフォルダーにunpack



    します。
  3. 新しいフォルダーをコミットします。
  4. 調査中の要素(ハイパーリンク、テーブルなど)をp。1からファイルに追加します。
  5. 変更したファイルを既存のフォルダーに解凍します。
  6. diffを研究し、不必要な変更(関係の置換、名前空間の順序など)を削除します。
  7. フォルダーをパックし、結果のファイルが開くことを確認します。
  8. 変更されたフォルダーをコミットします。


例1.テキストを強調表示する



実際に、太字のテキストのフォーマットを定義するタグを見つける方法を見てみましょう。







  1. 太字ではないテストテキストを使用してbold.docx



    ドキュメントを作成します。
  2. unpack bold.docx bold



    unpack bold.docx bold



  3. 結果をコミットします。
  4. Testというテキストを太字で強調表示します。
  5. unpack bold.docx bold



    unpack bold.docx bold



  6. 最初、diffは次のようになりました。


diff

詳細に検討してください。







docProps / app.xml



 @@ -1,9 +1,9 @@ - <TotalTime>0</TotalTime> + <TotalTime>1</TotalTime>
      
      





時間の変更は必要ありません。







docProps / core.xml



 @@ -4,9 +4,9 @@ - <cp:revision>1</cp:revision> + <cp:revision>2</cp:revision> <dcterms:created xsi:type="dcterms:W3CDTF">2017-02-07T19:37:00Z</dcterms:created> - <dcterms:modified xsi:type="dcterms:W3CDTF">2017-02-07T19:37:00Z</dcterms:modified> + <dcterms:modified xsi:type="dcterms:W3CDTF">2017-02-08T10:01:00Z</dcterms:modified>
      
      





ドキュメントのバージョンと変更日を変更しても、興味はありません。







word / document.xml



diff
 @@ -1,24 +1,26 @@ <w:body> - <w:pw:rsidR="0076695C" w:rsidRPr="00290C70" w:rsidRDefault="00290C70"> + <w:pw:rsidR="0076695C" w:rsidRPr="00F752CF" w:rsidRDefault="00290C70"> <w:pPr> <w:rPr> + <w:b/> <w:lang w:val="en-US"/> </w:rPr> </w:pPr> - <w:r> + <w:rw:rsidRPr="00F752CF"> <w:rPr> + <w:b/> <w:lang w:val="en-US"/> </w:rPr> <w:t>Test</w:t> </w:r> <w:bookmarkStart w:id="0" w:name="_GoBack"/> <w:bookmarkEnd w:id="0"/> </w:p> - <w:sectPr w:rsidR="0076695C" w:rsidRPr="00290C70"> + <w:sectPr w:rsidR="0076695C" w:rsidRPr="00F752CF">
      
      





w:rsidR



の変更は興味深いw:rsidR



ません-これはMicrosoft Wordの内部情報です。 ここで重要な変更







  <w:rPr> + <w:b/>
      
      





テスト付きの段落。 どうやら<w:b/>



要素もテキストを太字にします。 この変更を残し、残りをキャンセルします。







word / settings.xml



 @@ -1,8 +1,9 @@ + <w:proofState w:spelling="clean"/> @@ -17,10 +18,11 @@ + <w:rsid w:val="00F752CF"/>
      
      





また、太字のテキストに関連するものも含まれていません。 キャンセル。







7最初の変更( <w:b/>



追加)でフォルダーをパックし、 ドキュメントが開いて予期した内容を表示することを確認します。

8 変更をコミットします







例2.フッター



次に、より複雑な例を見てみましょう-フッターを追加します。

これが最初のコミットです。 テキスト123のフッターを追加し、ドキュメントを解凍します。 そのような差分は最初に取得されます:







diff







docProps/app.xml



およびdocProps/core.xml



への変更をすぐに除外します-最初の例と同じものです。







[Content_Types] .xml



 @@ -4,10 +4,13 @@ <Default Extension="xml" ContentType="application/xml"/> <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/> + <Override PartName="/word/footnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml"/> + <Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml"/> + <Override PartName="/word/footer1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"/>
      
      





フッターは明らかに必要なもののように見えますが、脚注と文末脚注はどうすればよいでしょうか? フッターを追加する際に必須ですか、それとも同時に作成されますか? この質問に対する答えは必ずしも簡単ではありません。主な方法を次に示します。









ドキュメントトを読む

ここまではさらに進んでいきます。







word / _rels / document.xml.rels



最初、diffは次のようになります。







diff
 @@ -1,8 +1,11 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> + <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings" Target="webSettings.xml"/> + <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/> <Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/> <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/> - <Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/> - <Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable" Target="fontTable.xml"/> + <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml"/> + <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/> + <Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/> </Relationships>
      
      





変更の一部は、Wordがリンクの順序を変更したという事実によるものであり、それらを削除することがわかります。







 @@ -3,6 +3,9 @@ + <Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer1.xml"/> + <Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/> + <Relationship Id="rId8" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes" Target="footnotes.xml"/>
      
      





フッター、脚注、文末脚注が再び表示されます。 それらはすべてメインドキュメントに関連付けられています。次に進みましょう。







word / document.xml



 @@ -15,10 +15,11 @@ </w:r> <w:bookmarkStart w:id="0" w:name="_GoBack"/> <w:bookmarkEnd w:id="0"/> </w:p> <w:sectPr w:rsidR="0076695C" w:rsidRPr="00290C70"> + <w:footerReference w:type="default" r:id="rId6"/> <w:pgSz w:w="11906" w:h="16838"/> <w:pgMar w:top="1134" w:right="850" w:bottom="1134" w:left="1701" w:header="708" w:footer="708" w:gutter="0"/> <w:cols w:space="708"/> <w:docGrid w:linePitch="360"/> </w:sectPr>
      
      





必要な変更のみがあるまれなケース。 sectPrからフッターへの明示的なリンクが表示されます 。 また、ドキュメントには脚注や文末脚注へのリンクがないため、それらは必要ないと想定できます。







word / settings.xml



diff
 @@ -1,19 +1,30 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <w:settings xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main" mc:Ignorable="w14 w15"> <w:zoom w:percent="100"/> + <w:proofState w:spelling="clean"/> <w:defaultTabStop w:val="708"/> <w:characterSpacingControl w:val="doNotCompress"/> + <w:footnotePr> + <w:footnote w:id="-1"/> + <w:footnote w:id="0"/> + </w:footnotePr> + <w:endnotePr> + <w:endnote w:id="-1"/> + <w:endnote w:id="0"/> + </w:endnotePr> <w:compat> <w:compatSetting w:name="compatibilityMode" w:uri="http://schemas.microsoft.com/office/word" w:val="15"/> <w:compatSetting w:name="overrideTableStyleFontSizeAndJustification" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/> <w:compatSetting w:name="enableOpenTypeFeatures" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/> <w:compatSetting w:name="doNotFlipMirrorIndents" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/> <w:compatSetting w:name="differentiateMultirowTableHeaders" w:uri="http://schemas.microsoft.com/office/word" w:val="1"/> </w:compat> <w:rsids> <w:rsidRoot w:val="00290C70"/> + <w:rsid w:val="000A7B7B"/> + <w:rsid w:val="001B0DE6"/>
      
      





そして、ここに脚注へのリンク、文書にそれらを追加する巻末注があります。







word / styles.xml



diff
 @@ -480,6 +480,50 @@ <w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/> <w:b/> <w:sz w:val="28"/> </w:rPr> </w:style> + <w:style w:type="paragraph" w:styleId="a4"> + <w:name w:val="header"/> + <w:basedOn w:val="a"/> + <w:link w:val="a5"/> + <w:uiPriority w:val="99"/> + <w:unhideWhenUsed/> + <w:rsid w:val="000A7B7B"/> + <w:pPr> + <w:tabs> + <w:tab w:val="center" w:pos="4677"/> + <w:tab w:val="right" w:pos="9355"/> + </w:tabs> + <w:spacing w:after="0" w:line="240" w:lineRule="auto"/> + </w:pPr> + </w:style> + <w:style w:type="character" w:customStyle="1" w:styleId="a5"> + <w:name w:val="  "/> + <w:basedOn w:val="a0"/> + <w:link w:val="a4"/> + <w:uiPriority w:val="99"/> + <w:rsid w:val="000A7B7B"/> + </w:style> + <w:style w:type="paragraph" w:styleId="a6"> + <w:name w:val="footer"/> + <w:basedOn w:val="a"/> + <w:link w:val="a7"/> + <w:uiPriority w:val="99"/> + <w:unhideWhenUsed/> + <w:rsid w:val="000A7B7B"/> + <w:pPr> + <w:tabs> + <w:tab w:val="center" w:pos="4677"/> + <w:tab w:val="right" w:pos="9355"/> + </w:tabs> + <w:spacing w:after="0" w:line="240" w:lineRule="auto"/> + </w:pPr> + </w:style> + <w:style w:type="character" w:customStyle="1" w:styleId="a7"> + <w:name w:val="  "/> + <w:basedOn w:val="a0"/> + <w:link w:val="a6"/> + <w:uiPriority w:val="99"/> + <w:rsid w:val="000A7B7B"/> + </w:style> </w:styles>
      
      





スタイルの変更は、スタイルの変更方法を探している場合にのみ興味があります。 この場合、この変更は削除できます。







word / footer1.xml



次に、フッター自体を見てみましょう(名前空間の一部は読みやすくするために省略されていますが、ドキュメント内にある必要があります)。







 <w:ftr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:pw:rsidR="000A7B7B" w:rsidRDefault="000A7B7B"> <w:pPr> <w:pStyle w:val="a6"/> </w:pPr> <w:r> <w:t>123</w:t> </w:r> </w:p> </w:ftr>
      
      





ここでは、テキスト123が表示されていますが、修正する必要があるのは、 <w:pStyle w:val="a6"/>



へのリンクを削除することだけです。







すべての変更を分析した結果、次のことを想定しています。









diffを次の変更セットに減らします:







最終差分







次に、 ドキュメントをパックして開きます。

すべてが正しく行われると、ドキュメントが開き、テキスト123のフッターが表示されます。そして、最後のコミットです。







したがって、変更を見つけるプロセスは、所定の結果を達成するのに十分な最小の変更セットを見つけることに削減されます。







練習する



関心のある変更を見つけたので、次の段階に進むのが論理的です。









ここでは、 XSLTXPathの知識が必要です。







既存のドキュメントのフッターを置換または追加する、かなり単純な変換を作成しましょう。 CachéObjectScript言語で記述しますが、それを知らなくても問題ではありません。 主にXSLTとアーカイバを呼び出します。 これ以上。 それでは始めましょう。







アルゴリズム



アルゴリズムは次のとおりです。







  1. ドキュメントを開梱します。
  2. フッターを追加します。
  3. リンクを[Content_Types].xml



    およびword/_rels/document.xml.rels



    書き込みword/_rels/document.xml.rels



  4. <w:sectPr>



    タグのword/document.xml



    で、 <w:sectPr>



    タグを追加するか、その中のフッターへのリンクを置き換えます。
  5. ドキュメントをパックします。


始めましょう。







開梱



CachéObjectScriptには、 $ zf(-1、oscommand)関数を使用してOSコマンドを実行する機能があります 。 unzipを呼び出して、 $ zf(-1)上ラッパーを使用してドキュメントを解凍します。







 ///  %3 (unzip)   %1   %2 Parameter UNZIP = "%3 %1 -d %2"; ///   source   targetDir ClassMethod executeUnzip(source, targetDir) As %Status { set timeout = 100 set cmd = $$$FormatText(..#UNZIP, source, targetDir, ..getUnzip()) return ..execute(cmd, timeout) }
      
      





フッターファイルを作成する



入力はフッターのテキストであり、in.xmlファイルに書き込みます。







 <xml>TEST</xml>
      
      





XSLT(ファイルはfooter.xsl)で、xmlタグのテキストを使用してフッターを作成します(名前空間の一部は省略されています。ここに完全なリストがあります )。







 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.openxmlformats.org/package/2006/relationships" version="1.0"> <xsl:output method="xml" omit-xml-declaration="no" indent="yes" standalone="yes"/> <xsl:template match="/"> <w:ftr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:p> <w:r> <w:rPr> <w:lang w:val="en-US"/> </w:rPr> <w:t> <xsl:value-of select="//xml/text()"/> </w:t> </w:r> </w:p> </w:ftr> </xsl:template> </xsl:stylesheet>
      
      





次に、 XSLTコンバーターを呼び出します







 do ##class(%XML.XSLT.Transformer).TransformFile("in.xml", "footer.xsl", footer0.xml")
      
      





結果はfooter0.xml



フッターfooter0.xml









 <w:ftr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:p> <w:r> <w:rPr> <w:lang w:val="en-US"/> </w:rPr> <w:t>TEST</w:t> </w:r> </w:p> </w:ftr>
      
      





メインドキュメントのリンクリストにフッターリンクを追加する



ルールとして識別子rId0



を持つリンクは存在しません。 ただし、XPathを使用して、存在しない識別子を取得できます。

word/_rels/document.xml.rels



_rels word/_rels/document.xml.rels



識別子rId0を持つfooter0.xml



へのリンクを追加しword/_rels/document.xml.rels









XSLT
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.openxmlformats.org/package/2006/relationships" version="1.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="no" /> <xsl:param name="new"> <Relationship Id="rId0" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer" Target="footer0.xml"/> </xsl:param> <xsl:template match="/*"> <xsl:copy> <xsl:copy-of select="$new"/> <xsl:copy-of select="@* | node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
      
      





ドキュメント内のリンクを規定します



次に、各<w:sectPr>



タグに<w:sectPr>



タグを追加するか、その中のフッターへのリンクを置き換える必要があります。 各<w:sectPr>



は、3つの<w:footerReference>



ことができることが判明しました。最初のページ、ページ、およびその他すべてに対して:







XSLT
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" version="1.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /> <xsl:template match="//@* | //node()"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="//w:sectPr"> <xsl:element name="{name()}" namespace="{namespace-uri()}"> <xsl:copy-of select="./namespace::*"/> <xsl:apply-templates select="@*"/> <xsl:copy-of select="./*[local-name() != 'footerReference']"/> <w:footerReference w:type="default" r:id="rId0"/> <w:footerReference w:type="first" r:id="rId0"/> <w:footerReference w:type="even" r:id="rId0"/> </xsl:element> </xsl:template> </xsl:stylesheet>
      
      





[Content_Types].xml



フッターを追加し[Content_Types].xml





/word/footer0.xml



application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml



型であるという情報を[Content_Types].xml



追加します。







XSLT
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schemas.openxmlformats.org/package/2006/content-types" version="1.0"> <xsl:output method="xml" omit-xml-declaration="yes" indent="no" /> <xsl:param name="new"> <Override PartName="/word/footer0.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"/> </xsl:param> <xsl:template match="/*"> <xsl:copy> <xsl:copy-of select="@* | node()"/> <xsl:copy-of select="$new"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
      
      





結果として



すべてのコードが公開されています。 次のように機能します。







 do ##class(Converter.Footer).modifyFooter("in.docx", "out.docx", "TEST")
      
      





どこで:









結論



XSLTとZIPのみを使用すると、docxドキュメント、xlsxテーブル、pptxプレゼンテーションを正常に処理できます。







未解決の質問



  1. 最初は、zip / unzip tの代わりに7zを使用したかったのです。これは1つのユーティリティであり、Windowsでより一般的であるためです。 しかし、Linuxで7zにパックされたドキュメントがMicrosoft Officeで開かないという問題に遭遇しました。 多く通話オプションを試しましたが、良い結果を得ることができませんでした。
  2. ECMA-376バージョン5の回路とコメントを含むXSDを探しています。 コメントなしのXSDバージョン5は、ECMA Webサイトからダウンロードできますが、コメントなしでは理解が困難です。 コメント付きのXSDバージョン2をダウンロードできます。


参照資料






All Articles