如何使用xsl从xml节点获取CDATA并转换为新的XML? [英] How to get CDATA from xml node using xsl and convert in a new XML?
本文介绍了如何使用xsl从xml节点获取CDATA并转换为新的XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好
我对包含CDATA代码的XML有问题.如果我们有以下XML:
I have a problem with a XML that contents CDATA code. If we have this XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<character>
<Body>
<methodResult>
<nodeOut>
<![CDATA[ <film>Indiana Jones and the Kingdom of the Crystal Skull</film>]]>
</nodeOut>
</methodResult>
</Body>
</character>
我们需要这个:
<film>Indiana Jones and the Kingdom of the Crystal Skull</film>
XSLT在哪里?我只想提取XML文件中的CDATA内容,然后删除其余的内容.我使用XSLT 1.0.
Where is the XSLT? I want extract only the CDATA content in a XML file and delete the rest. I use XSLT 1.0.
谢谢!
推荐答案
这将产生XML:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<!-- ignore this elements -->
<xsl:template match="role|actor|part"/>
<!-- get the remaining text and remove white-spaces -->
<xsl:template match="text()">
<xsl:value-of select="normalize-space(.)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
输出:
<?xml version="1.0" encoding="UTF-8"?><film>Indiana Jones and the Kingdom of the Crystal Skull</film>
这篇关于如何使用xsl从xml节点获取CDATA并转换为新的XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文