Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml xslt中两个字符串之间的字符串比较_Xml_Xslt - Fatal编程技术网

Xml xslt中两个字符串之间的字符串比较

Xml xslt中两个字符串之间的字符串比较,xml,xslt,Xml,Xslt,我使用下面的代码来检查两个字符串的内容是否相等,但它不起作用,因为我使用的是watson explorer id <xsl:variable name="str1" select="./td[4]"/> <xsl:variable name="str2" select="./td[2]"/> <xsl:if test="$str1 = $str2"> true </xsl:if> 真的 请告诉我如何使用xslt查找两个字符串的内容是否

我使用下面的代码来检查两个字符串的内容是否相等,但它不起作用,因为我使用的是watson explorer id

<xsl:variable name="str1" select="./td[4]"/>
<xsl:variable name="str2" select="./td[2]"/>

<xsl:if test="$str1 = $str2">
  true 
</xsl:if>

真的
请告诉我如何使用xslt查找两个字符串的内容是否相等,正如我尝试使用compare(str1,str2)时所做的那样,但它也不相等 在我使用xslt 1.0 verson时为我工作:

<Sample>`<AccountName1>SREE</AccountName1>`<AccountName2>SREE</AccountName2>`<SortCode>789-88-8907</SortCode>`<CardNumber>4545-6767-9876-8764</CardNumber>`<address>j-89-8999</address>`</Sample>
`SREE`SREE`789-88-8907`4545-6767-9876-8764`j-89-8999`
XSL:


第一:
第二:
两者都是一样的
两者都不同

请发布足够的代码,以便我们重现问题。不要说“它不起作用”;告诉我们你期望的结果是什么,你实际得到了什么。不要告诉我们有些东西“不起作用”。告诉我们它是如何失败的。Downvoting.Thank Michael现在我的问题已经解决了,实际上我用=运算符比较了两个字符串,所以对于相同的内容,当我在工具中启动调试时,它给出了false,我发现在其中一个字符串的开头添加了一个空格,因此它在与其他字符串进行比较时返回false
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:dp="http://www.datapower.com/extensions" >
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()"> 
<xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match = "*[local-name()='AccountName1' or local-name()='AccountName2']">
    <xsl:variable name = "var1">
 <xsl:value-of select = "/*[local-name()='Sample']/*[local-name()='AccountName1']/text()"/>
  </xsl:variable>
<xsl:variable name = "var2">
 <xsl:value-of select = "/*[local-name()='Sample']/*[local-name()='AccountName2']/text()"/>
</xsl:variable>
 <xsl:message dp:priority="debug"> First: <xsl:value-of select = "$var1"/> </xsl:message>
         <xsl:message dp:priority="debug"> Second: <xsl:value-of select = "$var2"/> </xsl:message>
<xsl:choose>
        <xsl:when test = "$var1=$var2">
<xsl:message dp:priority = "debug">Both are same </xsl:message>
                <xsl:copy>
                <xsl:value-of select = "."/>
            </xsl:copy>
</xsl:when>
        <xsl:otherwise>
            <xsl:message dp:priority = "debug">Both are different </xsl:message>
                <xsl:copy>
<xsl:value-of select="regexp:replace(*[local-name()='AccountName2'],'','',$var1)"/>
            </xsl:copy>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template> 


</xsl:stylesheet>