XSLT 转换错误地替换了字符
我有以下 XSLT 代码:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="POL">
<sql:SQLXML>
<sql:Execute as="Test" into="Test">
<sql:SQL>
select trans_type, trans_datetime, replace(convert(varchar, trans_datetime, 114), ':', '_') as trans_time, application_data from Acord_Transaction where transaction_id=
<xsl:value-of select="TRANSACTIONID" />
</sql:SQL>
</sql:Execute>
<xsl:if test="string-length(APPLICATIONDATA/parameters/noteid) > 0">
<sql:Execute as="newnote" into="newnotes">
<sql:SQL>
select * from notes where note_id=
<xsl:value-of select="APPLICATIONDATA/parameters/noteid" />
AND added_date='
<xsl:value-of select="APPLICATIONDATA/parameters/addeddate" />
'
</sql:SQL>
</sql:Execute>
</xsl:if>
</xsl:template>
问题:
APPLICATIONDATA
是一个从数据库初始化并包含 XML 代码的字符串字段。 sql:execute
完成后,输出 <
和 >
将替换为 <
和 <代码>>。
我需要一个在 sql:execute
之后应用的模板,以便执行结果成为有效 XML 代码。然后我可以从 xsl:if
运行 XPath。
I've the following XSLT code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="POL">
<sql:SQLXML>
<sql:Execute as="Test" into="Test">
<sql:SQL>
select trans_type, trans_datetime, replace(convert(varchar, trans_datetime, 114), ':', '_') as trans_time, application_data from Acord_Transaction where transaction_id=
<xsl:value-of select="TRANSACTIONID" />
</sql:SQL>
</sql:Execute>
<xsl:if test="string-length(APPLICATIONDATA/parameters/noteid) > 0">
<sql:Execute as="newnote" into="newnotes">
<sql:SQL>
select * from notes where note_id=
<xsl:value-of select="APPLICATIONDATA/parameters/noteid" />
AND added_date='
<xsl:value-of select="APPLICATIONDATA/parameters/addeddate" />
'
</sql:SQL>
</sql:Execute>
</xsl:if>
</xsl:template>
Problem:
APPLICATIONDATA
is a string field that is initialized from the database and contains XML code. After the sql:execute
completes, the output <
and >
is replaced by <
and >
.
I need a template that will be applied after sql:execute
, so that the result of the execution becomes valid XML code. Then I can run the XPath from xsl:if
on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
XSLT 在二维的树结构(XML)上运行。
数据库中的标记已被展平为一维字符串,被严重破坏。
必须通过取消转义转义字符来扭转这种野蛮行为,然后可以像往常一样使用 XSLT 处理恢复的 XML。
取消转义本身可以使用 XSLT 2.0 来完成,但绝对没有什么紧迫的理由说明为什么应该使用 XSLT。
XSLT operates on tree structures (XML) which are two-dimensional).
What you have in the database is a severely destroyed markup, having been flattened to a one-dimensional string.
This barbaric action must be reversed by unescaping the escaped characters, then the restored XML can be processed with XSLT as usual.
The unescaping itself could be done using XSLT 2.0 but there is absolutely no pressing reason why XSLT should be used for this.
不幸的是,没有可靠的或内置的方法可以在直接的 XSLT 中执行此操作。如果可能,您不应将 XML 数据存储在数据库中,并以这种方式转义标记。请参阅:XSL 字符转义问题
Unfortunately, there is not a reliable or built-in way to do this in straight-up XSLT. If possible, you shouldn't store XML data in your database with the markup escaped in that way. See: XSL character escape problem
正如 James 所说,在 XSLT 的范围内无法做到这一点。但是,根据您的解析引擎,有一些特定于风味的方法可以实现此目的。请参阅这篇文章了解一些想法: XSLT;将转义文本解析为节点集并提取子元素
Like James said, there is no way to do this within the confines of XSLT. However, depending on your parsing engine, there are flavor-specific ways to accomplish this. See this post for a couple ideas: XSLT; parse escaped text to a node-set and extract subelements