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-l开发者_运维技巧ength(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.
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.
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
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
精彩评论