如何强制 xslt 转换将数据加载到 cdata 部分? [英] How do I force xslt transformation to load data into cdata sections?

查看:38
本文介绍了如何强制 xslt 转换将数据加载到 cdata 部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户要求我提供给他们的 xml 中的所有文本都在 CDATA 部分中.我知道文本不需要在 CDATA 中,因为它在提供给客户端时已经被解析和转换.但是,无论我多么确定,他们仍然需要 CDATA 部分.叹气.

I have a client who requires all text in the xml I supply them with to be in CDATA sections. I understand that text should not need to be in CDATA as it has already been parsed and transformed when it is supplied to the client. However, no matter how sure I am, they still need the CDATA sections. Sigh.

我正在使用 Saxon 9.3 处理我的数据,使用命令行转换命令.

I am processing my data with Saxon 9.3, using the command line transform command.

推荐答案

正如您的问题标题谈到 XSLT 并且您的问题被标记为 XSLT,确保结果元素的内容被序列化为 CDATA 部分的 XSLT 方法是在 xsl:output 元素上使用 cdata-section-elements 属性 (http://www.w3.org/TR/xslt20/#serialization) 列出要作为 CDATA 部分输出的所有元素.因此,如果您在编写样式表时知道要作为 CDATA 部分输出的元素,那么将它们列在该属性中就很简单了.这有帮助吗?或者您想使用 XSLT 对任意 XML 进行后处理以添加 CDATA 部分?

Well as your question title talks about XSLT and your question is flagged as XSLT, the XSLT way to ensure a result element's content is serialized as a CDATA section is to use the cdata-section-elements attribute on the xsl:output element (http://www.w3.org/TR/xslt20/#serialization) listing all elements you want to output as CDATA sections. Thus if you know the elements you want to output as CDATA sections when writing the stylesheet it is a simple as listing them in that attribute. Does that help? Or do you want to postprocess arbitrary XML with XSLT to add CDATA sections?

这篇关于如何强制 xslt 转换将数据加载到 cdata 部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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