保留 CDATA 进行 xstl 转换? [英] Keep CDATA for xstl transformation?

查看:109
本文介绍了保留 CDATA 进行 xstl 转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自 XML 文档的 saxon 进行 xstl 转换.该文档不是标准有效的 XML,我想保留所有在其中找到的 <![CDATA[< 元素.

I'm doing a xstl transformation with saxon from an XML document. The doc is not standard-valid XML, and I want to preserve all <![CDATA[< elements that are found in there.

但是使用 .xsl 文件进行转换

However using the .xsl file for transformation with

Transformer trans = TransformerFactory.newInstance().newTransformer(new StreamSource(new File("foo.xsl"));
trans.transform(new StreamSource(new File("foo.xml"), new StreamResult(new File("output.xml")));

导致剥离这些 CDATA 条目.我怎样才能防止这种情况?

results in stripping out these CDATA entries. How can I prevent this?

推荐答案

您不能,因为 xslt 使用的数据模型中是否不提供源自 cdata 部分的文本的区别.但是,您可以在样式表中定义将某些结果元素包装在 cdata 中.这是使用 cdata-section-elements 属性完成的样式表中的 xsl:output 元素.

You can't, as the distinction whether a text originated from a cdata section is not available in the datamodel used by xslt. You can however define in your stylesheet that certain result elements are to be wrapped inside cdata. This is done using the cdata-section-elements attribute of the xsl:output element in your stylesheet.

这篇关于保留 CDATA 进行 xstl 转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆