我正處在一個將基於Word的文檔轉換爲XML的非常痛苦的過程中。我遇到了以下問題:混合內容和字符串操作清理
<?xml version="1.0" encoding="UTF-8"?>
<root>
<p>
<element>This one is taken care of.</element> Some more text. „<hi rend="italics">Is this a
quote</hi>?」 (Source). </p>
<p>
<element>This one is taken care of.</element> Some more text. „<hi rend="italics">This is a
quote</hi>」 (Source). </p>
<p>
<element>This one is taken care of.</element> Some more text. „<hi rend="italics">This is
definitely a quote</hi>!」 (Source). </p>
<p>
<element>This one is taken care of.</element> Some more text.„<hi rend="italics">This is a
first quote</hi>」 (Source). „<hi rend="italics">Sometimes there is a second quote as
well</hi>!?」 (Source). </p>
</root>
<p>
節點有混合內容。 <element>
我已在之前的迭代中處理過。但現在問題是引號和來源部分出現在<hi rend= "italics"/>
和部分作爲文本節點。
如何使用XSLT 2.0:
- 匹配立即被它的最後一個字符是「「「文本節點之前的所有節點
<hi rend="italics">
? - 輸出
<hi rend="italics">
的內容爲<quote>...</quote>
,除掉引號(「」「和」「」),但在<quote/>
之內包含任何問題和感嘆號,緊接在<hi rend="italics">
的兄弟之後出現? - 將
<hi rend="italics">
節點之後的「(」和「)」之間的文本節點轉換爲<source>...</source>
而不包含括號。 - 包括最終的全站。
換句話說,我的輸出應該是這樣的:
<root>
<p>
<element>This one is taken care of.</element> Some more text. <quote>Is this a quote?</quote> <source>Source</source>.
</p>
<p>
<element>This one is taken care of.</element> Some more text. <quote>This is a quote</hi> <source>Source</source>.
</p>
<p>
<element>This one is taken care of.</element> Some more text. <quote>This is definitely a quote!</hi> <source>Source</source>.
</p>
<p>
<element>This one is taken care of.</element> Some more text. <quote>This is a first quote</quote> <source>Source</source>. <quote>Sometimes there is a second quote as well!?</quote> <source>Source</source>.
</p>
</root>
我從來沒有處理混合內容和字符串操作這樣整個事情真的扔我。我將非常感謝您的提示。
輸入文檔中的問號和感嘆號在'hi'元素之外,但是在期望的輸出中,它們在'quote'元素中。這看起來很奇怪。是對的?請確認。 –
這是意圖,是的。 – Tench