xsl:使用 cdata-section-elements 输出,不将目标 cdata-section-element 封装在 CDATA 标记中
我正在尝试:
<!-- Arrive at the target XQuery -->
<p:processor name="oxf:xslt">
<p:input name="config">
<xsl:stylesheet version="2.0">
<xsl:output method="xml" version="1.0"
encoding="iso-8859-1" indent="yes" cdata-section-elements="text"/>
<xsl:template match="/">
<xsl:variable name="apps" select="doc('input:instance')//APPLICATION"/>
<jaxrx:query>
<text>
xquery version "1.0";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
let $dataSet := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='dataSet']/value" />
let $databaseName := <xsl:value-of select="/Configuration/XMLDB/Name/text()" />
let $applicationID := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='applicationID']/value" />
let $finalURL := fn:concat($databaseName, "/",$dataSet)
let $applicationsModified := '<xsl:copy-of select="$apps"/>'
<!-- disable-output-escaping not supported by Orbeon xslt processor
(: let $applicationsModified := '<xsl:text disable-output-escaping="yes">
<![CDATA[<]]>
</xsl:text>
<xsl:text disable-output-escaping="yes">![CDATA[</xsl:text>
<xsl:copy-of select="$apps"/>
<xsl:text>]]</xsl:text>
<xsl:text disable-output-escaping="yes">
<![CDATA[>]]></xsl:text>' :) -->
for $all in fn:collection($finalURL)
for $anApp in $all/APPLICATION[APPLICATION_ID=$applicationID]
return
(
replace node $anApp with $applicationsModified
)
</text>
</jaxrx:query>
</xsl:template>
</xsl:stylesheet>
</p:input>
<p:input name="data" href="#configuration"/>
<p:input name="request" href="#request"/>
<p:input name="instance" href="#instance"/>
<p:output name="data" id="TargetXQuery"/>
</p:processor>
希望产生类似的结果
<jaxrx:query><text><![CDATA[text of xquery with embedded xml]]></text></jaxrx:query>
,但文本(元素名称)元素的文本内容不会封装在 CDATA 部分中。有大佬指点一下为什么吗?
我还尝试设置 cdata-section-elements="jaxrx:text" 而不是 cdata-section-elements="text",但我仍然得到
<text>text of xquery with embedded xml</text>
,所以 CDATA 部分中没有封装...
I am trying:
<!-- Arrive at the target XQuery -->
<p:processor name="oxf:xslt">
<p:input name="config">
<xsl:stylesheet version="2.0">
<xsl:output method="xml" version="1.0"
encoding="iso-8859-1" indent="yes" cdata-section-elements="text"/>
<xsl:template match="/">
<xsl:variable name="apps" select="doc('input:instance')//APPLICATION"/>
<jaxrx:query>
<text>
xquery version "1.0";
declare namespace fn="http://www.w3.org/2005/xpath-functions";
let $dataSet := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='dataSet']/value" />
let $databaseName := <xsl:value-of select="/Configuration/XMLDB/Name/text()" />
let $applicationID := <xsl:value-of select="doc('input:request')/request/parameters/parameter[name='applicationID']/value" />
let $finalURL := fn:concat($databaseName, "/",$dataSet)
let $applicationsModified := '<xsl:copy-of select="$apps"/>'
<!-- disable-output-escaping not supported by Orbeon xslt processor
(: let $applicationsModified := '<xsl:text disable-output-escaping="yes">
<![CDATA[<]]>
</xsl:text>
<xsl:text disable-output-escaping="yes">![CDATA[</xsl:text>
<xsl:copy-of select="$apps"/>
<xsl:text>]]</xsl:text>
<xsl:text disable-output-escaping="yes">
<![CDATA[>]]></xsl:text>' :) -->
for $all in fn:collection($finalURL)
for $anApp in $all/APPLICATION[APPLICATION_ID=$applicationID]
return
(
replace node $anApp with $applicationsModified
)
</text>
</jaxrx:query>
</xsl:template>
</xsl:stylesheet>
</p:input>
<p:input name="data" href="#configuration"/>
<p:input name="request" href="#request"/>
<p:input name="instance" href="#instance"/>
<p:output name="data" id="TargetXQuery"/>
</p:processor>
With the hope of producing a result like
<jaxrx:query><text><![CDATA[text of xquery with embedded xml]]></text></jaxrx:query>
But the text (name of element) element's textual content does not get encapsulated in a CDATA section. Any pointers why?
I have also tried setting cdata-section-elements="jaxrx:text" instead of cdata-section-elements="text", but I still get
<text>text of xquery with embedded xml</text>
, so no encapsulation in a CDATA section...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CDATA 部分不会按原样保留在管道中。然而,等效的 XML InfoSet 被保留。例如,如果您使用 CDATA 部分转义 & 符号:
当它通过管道时,您最终可能会得到以不同方式转义的 & 符号,如下所示:
如果您需要将 XQuery 作为文本嵌入 XML 元素中,请随意在管道中编写如下内容:
如果使用“debug”属性输出此内容,则不会看到 CDATA,但 XQuery 将被正确转义。
The CDATA sections are not preserved as-is in a pipeline. However, the equivalent XML InfoSet is preserved. So for instance, if you escape an ampersand character using a CDATA section:
When this goes through a pipeline, you might end up with the ampersand escaped differently, as in:
If you need to embed XQuery as text in an XML element, feel free to write something like the following in your pipeline:
If you output this with a "debug" attribute, you won't see the CDATA, but your XQuery will be properly escaped.