[英]ibm-datapower gives “>” in place of “>” and “<” in place of “<” in resulting XML for text data using XSLT
In one of my application, I am trying to convert the response of my service with the help of xslt on datapower. 在我的一个应用程序中,我试图借助xslt on datapower转换服务的响应。 In one of the response scenario, I need to show an xml something like below:
在一种响应方案中,我需要显示一个类似于以下内容的xml:
<data contentType="text/xml;charset=utf-8" contentLength="80"><![CDATA[Your request cannot be processed]]></data>
But my XSLT fails on datapower and it shows ">"
但是我的XSLT在数据能力上失败,并且显示
">"
and "<"
和
"<"
in place of ">"
and "<"
. 代替
">"
和"<"
。
Below are my some of the attempted templates. 以下是我尝试的一些模板。 Kindly have a look and suggest any correction:
请看一下并提出任何更正建议:
Attempt 1:Tried with ">
" and "<"
尝试1:尝试使用
">
”和"<"
<xsl:param name="mask" select="'Your request cannot be processed'"/>
<xsl:template match="*" mode="copyFault">
<xsl:text disable-output-escaping="yes"><data contentType="text/xml;charset=utf-8" contentLength="80"><![CDATA[</xsl:text>
<xsl:value-of select="$mask" />
<xsl:text disable-output-escaping="yes">]]></data></xsl:text>
</xsl:template>
Attempt 2:Tried with HEX values 尝试2:尝试使用十六进制值
<xsl:param name="mask" select="'Your request cannot be processed'"/>
<xsl:variable name="lessThan" select="'<'"/>
<xsl:variable name="GreaterThan" select="'>'"/>
<xsl:template match="*" mode="copyFault">
<xsl:value-of disable-output-escaping = "yes" select="$lessThan"/>
<xsl:text>data contentType="text/xml;charset=utf-8" contentLength="80"</xsl:text>
<xsl:value-of disable-output-escaping = "yes" select="$GreaterThan"/>
<xsl:value-of disable-output-escaping = "yes" select="$lessThan"/>
<xsl:text>![CDATA[</xsl:text>
<xsl:value-of select="$mask" />
<xsl:text>]]</xsl:text>
<xsl:value-of disable-output-escaping = "yes" select="$GreaterThan"/>
<xsl:value-of disable-output-escaping = "yes" select="$lessThan"/>
<xsl:text>/data</xsl:text>
<xsl:value-of disable-output-escaping = "yes" select="$GreaterThan"/>
</xsl:template>
Please let me know what should I do to get the xml in proper format from datapower. 请让我知道我应该怎么做才能从datapower获得正确格式的xml。
Thanks. 谢谢。
The usual way in XSLT to output a certain XML element is a literal result element so using XSLT中输出特定XML元素的常用方法是文字结果元素,因此使用
<data contentType="text/xml;charset=utf-8" contentLength="80">Your request cannot be processed</data>
in your XSLT will then output that element in the result. 然后在XSLT中将在结果中输出该元素。 If you want to populate the element with a variable or parameter value then use eg
如果要用变量或参数值填充元素,请使用例如
<data contentType="text/xml;charset=utf-8" contentLength="80"><xsl:value-of select="$mask"/></data>
If the XSLT processor is in charge of serializing the result to a file or string and you want some element like the data
element to have a CDATA section as the content then declare eg <xsl:output cdata-section-elements="data"/>
as a child of xsl:stylesheet
(or xsl:transform
if you have named the root element that way). 如果XSLT处理器负责将结果序列化为文件或字符串,并且您希望诸如
data
元素之类的某些元素具有CDATA节作为内容,则声明例如<xsl:output cdata-section-elements="data"/>
作为xsl:stylesheet
(或xsl:transform
如果您已经用这种方式命名根元素)的子级。
disable-output-escaping
is a thoroughly nasty feature: it doesn't work on all processors, and if it's supported at all, it only works when the transformation output is fed directly into an XSLT-aware serializer, so it depends on how you are running the transformation. disable-output-escaping
是一个非常讨厌的功能:并非在所有处理器上都有效,并且如果完全受支持,则仅在将转换输出直接输入到支持XSLT的序列化器中时才起作用,因此它取决于您正在运行转换。
It's much better to avoid disable-output-escaping
when you can, and there's certainly no evidence you need it here. 最好在可能的情况下避免使用
disable-output-escaping
,并且当然没有证据表明您需要它。 The requirement to output a CDATA section is somewhat unusual (any well-written application reading XML doesn't care whether the text is in a CDATA section or not), but if you really need it, then you can usually achieve it using <xsl:output cdata-section-elements="data"/>
. 输出CDATA部分的要求有些不寻常(任何编写良好的读取XML的应用程序都不关心文本是否在CDATA部分中),但是如果确实需要,通常可以使用
<xsl:output cdata-section-elements="data"/>
来实现<xsl:output cdata-section-elements="data"/>
。 (Though again, this only works if the output is fed into an XSLT-aware serializer.) (尽管如此,这仅在将输出馈入支持XSLT的串行器中时有效。)
Certainly, generating start and end tags using disable-output-escaping
is very poor practice. 当然,使用
disable-output-escaping
生成开始和结束标签是非常差的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.