How to use XML wrapped in CDATA inside another XML for XSL transformation?

こ雲淡風輕ζ 提交于 2019-12-13 14:50:39

问题


An XML document contains another XML element, which is wrapped in CDATA.

How can the wrapped XML be used for XSL and XSL-FO transformation (version 1)?


回答1:


This is not possible with standard XSLT 1.0 or 2.0, in a single transformation.

It can be done using Saxon 9 Professional Edition or Enterprise Edition. These products have a saxon:parse() extension function. Or use the XPath 3.0 parse-xml() function, which is also supported by recent versions of Saxon PE/EE.


As @grtjn points out, it is possible to do it with a two-pass process. Stylesheet 1 turns the CDATA-wrapped text into parseable XML (using <xsl:value-of select="whatever" disable-output-escaping="yes"/>). Stylesheet 2 then processes the serialized result produced by stylesheet 1.




回答2:


If you are willing to take multiple transformation steps then it is possible. Output the relevant section with disable-output-escaping to turn the escaped XML into valid XML. Process it in a subsequent step.

It does require the escaped XML to be well-formed. And some parsers require the intermediate result to be serialized (to disk or else) first to make sure the escaped XML is properly unescaped before it enters the subsequent transformations.



来源:https://stackoverflow.com/questions/9093934/how-to-use-xml-wrapped-in-cdata-inside-another-xml-for-xsl-transformation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!