处理msxml的XSLT大整数(int64)
当尝试对xslt模板中的大整数(int64)进行计算时,我得到了错误的结果,因为xslt中不支持本机64位整数(xslt数字是64位双精度)。我在WindowsXPSP3上使用MSXML6.0。在Windows上有什么解决方法吗处理msxml的XSLT大整数(int64),xslt,types,msxml,biginteger,Xslt,Types,Msxml,Biginteger,当尝试对xslt模板中的大整数(int64)进行计算时,我得到了错误的结果,因为xslt中不支持本机64位整数(xslt数字是64位双精度)。我在WindowsXPSP3上使用MSXML6.0。在Windows上有什么解决方法吗 <tables> <table> <table_schem>REPADMIN</table_schem> <table_name>TEST_DESCEND_IDENTITY_BIGINT&l
<tables>
<table>
<table_schem>REPADMIN</table_schem>
<table_name>TEST_DESCEND_IDENTITY_BIGINT</table_name>
<column>
<col_name>COL1</col_name>
<identity>
<col_min_val>9223372036854775805</col_min_val>
<col_max_val>9223372036854775805</col_max_val>
<autoincrementvalue>9223372036854775807</autoincrementvalue>
<autoincrementstart>9223372036854775807</autoincrementstart>
<autoincrementinc>-1</autoincrementinc>
</identity>
</column>
</table>
</tables>
重新管理
测试\u下降\u标识\u BIGINT
可乐
9223372036854775805
9223372036854775805
9223372036854775807
9223372036854775807
-1
由于大整数在64位double中的表示不精确(我假设),此测试返回true,但如果我能告诉xslt处理器对数字数据使用int64而不是默认的64位double,则实际上返回false,因为大整数是xml输入中数字的实际数据类型
<xsl:when test="autoincrementvalue =
(col_min_val + autoincrementinc)">
<xsl:value-of select="''"/>
</xsl:when>
这是完整的模板
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<!--Reseed Derby identity column-->
<xsl:output omit-xml-declaration='yes' method='text' />
<xsl:param name="stmtsep">;</xsl:param>
<xsl:param name="schemprefix"></xsl:param>
<xsl:template match="tables">
<xsl:variable name="identitycount" select="count(table/column/identity)"></xsl:variable>
<xsl:for-each select="table/column/identity">
<xsl:variable name="table_schem" select="../../table_schem"></xsl:variable>
<xsl:variable name="table_name" select="../../table_name"></xsl:variable>
<xsl:variable name="tablespec">
<xsl:if test="$schemprefix">
<xsl:value-of select="$table_schem"/>.</xsl:if><xsl:value-of
select="$table_name"/></xsl:variable>
<xsl:variable name="col_name" select="../col_name"></xsl:variable>
<xsl:variable name="newstart">
<xsl:choose>
<xsl:when test="autoincrementinc > 0">
<xsl:choose>
<xsl:when test="col_max_val = '' and
autoincrementvalue = autoincrementstart">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:when test="col_max_val = ''">
<xsl:value-of select="autoincrementstart"/>
</xsl:when>
<xsl:when test="autoincrementvalue =
(col_max_val + autoincrementinc)">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:when test="(col_max_val + autoincrementinc) <
autoincrementstart">
<xsl:value-of select="autoincrementstart"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="col_max_val + autoincrementinc"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="autoincrementinc < 0">
<xsl:choose>
<xsl:when test="col_min_val = '' and
autoincrementvalue = autoincrementstart">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:when test="col_min_val = ''">
<xsl:value-of select="autoincrementstart"/>
</xsl:when>
<xsl:when test="autoincrementvalue =
(col_min_val + autoincrementinc)">
<xsl:value-of select="''"/>
</xsl:when>
<xsl:when test="(col_min_val + autoincrementinc) >
autoincrementstart">
<xsl:value-of select="autoincrementstart"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="col_min_val + autoincrementinc"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="not(position()=1)"><xsl:text>
</xsl:text></xsl:if>
<xsl:choose>
<!--restart with ddl changes both the next identity value AUTOINCREMENTVALUE and
the identity start number AUTOINCREMENTSTART eventhough in this casewe only want
to change only the next identity number-->
<xsl:when test="$newstart != '' and
$newstart != autoincrementvalue">alter table <xsl:value-of
select="$tablespec"/> alter column <xsl:value-of
select="$col_name"/> restart with <xsl:value-of
select="$newstart"/><xsl:if test="$identitycount>1">;</xsl:if></xsl:when>
<xsl:otherwise>-- reseed <xsl:value-of select="$tablespec"/> is not necessary</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
;
.
alter table alter column restart with;
--没有必要重新设定种子
这件事有什么解决办法吗
窗户
否,除非使用XSLT2.0处理器,如Saxon或AltovaXML
在XSLT2.0中,使用了XPath2.0,它支持xs:decimal,这为您提供了所需的精度。对于Saxon,也可以只使用xs:integer,因为Saxon和Altova都实现了大整数算法
这里是一个XSLT2.0样式表(默认情况下使用xs:integer):
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"9223372036854775805 + (-1)"/>
</xsl:template>
</xsl:stylesheet>
9223372036854775804
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"xs:decimal(9223372036854775805) + (-1)"/>
</xsl:template>
</xsl:stylesheet>
这里是一个显式使用xs:decimal的XSLT2.0样式表:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"9223372036854775805 + (-1)"/>
</xsl:template>
</xsl:stylesheet>
9223372036854775804
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"xs:decimal(9223372036854775805) + (-1)"/>
</xsl:template>
</xsl:stylesheet>
Saxon 9.x和AltovaXML2010再次产生正确的结果
这件事有什么解决办法吗
窗户
否,除非使用XSLT2.0处理器,如Saxon或AltovaXML
在XSLT2.0中,使用了XPath2.0,它支持xs:decimal,这为您提供了所需的精度。对于Saxon,也可以只使用xs:integer,因为Saxon和Altova都实现了大整数算法
这里是一个XSLT2.0样式表(默认情况下使用xs:integer):
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"9223372036854775805 + (-1)"/>
</xsl:template>
</xsl:stylesheet>
9223372036854775804
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"xs:decimal(9223372036854775805) + (-1)"/>
</xsl:template>
</xsl:stylesheet>
这里是一个显式使用xs:decimal的XSLT2.0样式表:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"9223372036854775805 + (-1)"/>
</xsl:template>
</xsl:stylesheet>
9223372036854775804
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"xs:decimal(9223372036854775805) + (-1)"/>
</xsl:template>
</xsl:stylesheet>
Saxon 9.x和AltovaXML2010再次生成正确的结果感谢您提供的信息。恐怕我现在只能使用msxml 6.0了。由于我是从sql select语句的结果集生成输入xml,正确计算的一种可行方法是在数据库select语句中进行计算,并将newstart元素添加到输入xml中;然后xslt处理器将不做任何计算,只检查$newstart的空字符串以生成信息的输出。恐怕我现在只能使用msxml 6.0了。由于我是从sql select语句的结果集生成输入xml,正确计算的一种可行方法是在数据库select语句中进行计算,并将newstart元素添加到输入xml中;然后xslt处理器将不做任何计算,只检查$newstart的空字符串以生成输出