如何在XSLT中解析CDATA元素中的XML DOM?
发布时间:2020-12-15 23:57:54 所属栏目:百科 来源:网络整理
导读:说我有一个 XML文件,如: library books ![CDATA[genrenameSci-fi/namecount2/count/genre]] book name Some Book /name author Some author /author book book name Another Book /name author Another author /author book books/library 我想在xslt转换器
说我有一个
XML文件,如:
<library> <books> <![CDATA[<genre><name>Sci-fi</name><count>2</count></genre>]]> <book> <name> Some Book </name> <author> Some author </author> <book> <book> <name> Another Book </name> <author> Another author </author> <book> <books> </library> 我想在xslt转换器中读取CDATA元素’name’,并将其值放在标签的vaue中.我该怎么做呢? AFAIK,我们不能在CDATA的内容上使用xpath.这有什么黑客/解决方法吗?我想在XSLT中严格执行此操作.
由于CDATA块是(部分)文本节点,因此您可以在两个“标签”之间提取文本,例如像这样:
<xsl:template match="text()"> <xsl:value-of select="substring-before(substring-after(.,'<name>'),'</name>')"/> </xsl:template> 这只是一个快速的想法.如果CDATA中有多个名称“element”,则只需递归地多次应用上面的表达式. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |