我有一個帶有以下標記和數據的xml文件main.xml。根據外部xml文件搜索關鍵字並替換xml文件中的文本
main.xml
<xml>
<content>
<para>
This is a para.
</para>
<sub para>
This is para.
</sub para>
</content>
</xml>
我有,我們需要找到在上面的XML任何地方和替換關鍵字值的關鍵字列表另一個XML文件keyword.xml。
keyword.xml
<xml>
<keywordList>
<keyword>
<value>para</value>
<replace> paragraph </replace>
</keyword>
<keyword>
<value>is</value>
<replace>IS</replace>
</keyword>
</xml>
我們能夠做到在XSLT這樣輸出應該是
output
<xml>
<content>
<para>
This IS a paragraph.
</para>
<sub para>
This IS paragraph.
</sub para>
</content>
</xml>
您的輸入XML格式不正確。 – 2012-03-27 09:10:33
請參閱http://stackoverflow.com/questions/2145004/efficient-code-for-replacing-a-text-node-with-some-other-text-using-xslt – Jon 2012-03-27 09:12:59
您僅限於XSLT1嗎?還是可以使用xslt2 。這在xslt2中使用xsl:analyze-string是微不足道的,但在xslt1中,字符串處理相當基本,所以您需要在空白區域(可能)分割遞歸模板。 – 2012-03-27 10:21:08