gpt4 book ai didi

xslt - XSL - 如果变量来自字符串,如何将其设置为整数

转载 作者:行者123 更新时间:2023-12-05 01:45:53 24 4
gpt4 key购买 nike

XPTY0004 : The operator ' + ' is not defined for operands of type xs:string and xs:integer

输入:

<?xml version="1.0" encoding="UTF-8"?>
<LeveL Plan="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">


<space2000>
<values>
<value jak="77" rak="12"</value>
<value jak="66" rak="345"></value>
<value jak="-50" rak="67"></value>
<value jak="-30" rak="-89">1</value>
</values>

</space2000>


</LeveL>

我的尝试:

<xsl:stylesheet version="2.0" 
xmlns:fn ="http://www.w3.org/2005/xpath-functions"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="/">
<xsl:for-each select="(LeveL/space2000/values)">
<xsl:variable name="JJJ" select="(format-number(((value/@jak) div 2),'0'))"/>
<xsl:variable name="RRR" select="format-number(((value/@rak) div 2),'0')"/>
<xsl:text>
O
</xsl:text>
<xsl:text>LA</xsl:text>
<xsl:value-of select="$JJJ"></xsl:value-of>
<xsl:text> </xsl:text><xsl:text>LO</xsl:text>
<xsl:value-of select="$RRR"></xsl:value-of>
<xsl:text>
O
</xsl:text>

<xsl:choose>
<xsl:when test="( $JJJ > '0')">
<xsl:value-of select="A"/>
</xsl:when>
<xsl:when test="( $JJJ < '0')">
<xsl:value-of select="B"/>
</xsl:when>
<xsl:when test="( $RRR > '0')">
<xsl:value-of select="C"/>
</xsl:when>
<xsl:when test="( $RRR < '0')">
<xsl:value-of select="D"/>
</xsl:when>
<xsl:when test="( ( $RRR + '50') < '0' )">
<xsl:value-of select="X"/>
</xsl:when>
<xsl:when test="( '-100' < ( $RRR + '1') < '100' )">
<xsl:value-of select="X"/>
</xsl:when>


</xsl:choose>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

所以我想收到类似的东西:一个C乙丁X

但是 xsl

不喜欢+(不相信它的整数:)

不喜欢<(另一种方式>对他来说是可以接受的:)

SO MY QUESTION IS

a) How to set variable (or element) as integer able to do mathematics?

b) How to test if variable is bigger than -100 and smaller than 100 ?

请嘿嘿嘿:)

最佳答案

首先,一个纯 XML 问题,与 XSLT 无关:"<"必须转义为 "&lt;" . (但是对于 XSLT 2.0,使用“lt”运算符通常比“<”更方便。

第二点:不要将数字放在引号中。写 50,而不是 '50'。

第三:声明变量的类型是个好主意,这样会更清楚发生了什么。例如

<xsl:variable name="JJJ" select="format-number(...)" as="xs:string"/>

最后,如果要添加一个字符串和一个数字,请先使用 xs:integer() 将字符串转换为数字。 , xs:double() ,或 number()功能。

关于xslt - XSL - 如果变量来自字符串,如何将其设置为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39615813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com