Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.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
Xslt 如何检查字符串是否包含在列表中?_Xslt_Xpath - Fatal编程技术网

Xslt 如何检查字符串是否包含在列表中?

Xslt 如何检查字符串是否包含在列表中?,xslt,xpath,Xslt,Xpath,XSLT代码: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr bgcolor=

XSLT代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd[artist='Bob Dylan']">
      <tr>
        <td><xsl:value-of select="title"/></td>
        <td><xsl:value-of select="artist"/></td>
      </tr>
      </xsl:for-each>
    **<xsl:value-of select="sum(catalog/cd[artist='Bob Dylan' and extra[not(contains(tests/test,'CD'))]]/price)"/>**
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

我一直在抓救命稻草,所以我希望有人能启发我。提前谢谢

在原始XSLT中,表达式中包含此内容

extra[not(contains(tests/test,'CD'))]
contains
是一个字符串函数,它接受两个字符串作为参数。如果您向它传递一个节点,它将首先将其转换为字符串。但在本例中,您传递的是一个节点集。在XSLT1.0中,它将仅将其中的第一个节点转换为字符串,这就是它不拾取最后一张
cd
的原因。(在XSLT1.0中,传入由多个节点组成的节点集会引发错误)

您需要这样做,以便将
包含的
作为条件应用于每个
测试

<xsl:value-of select="sum(catalog/cd[artist='Bob Dylan' and extra[not(tests/test[contains(., 'CD')])]]/price)"/>

或者你可以把它简化成这样

<xsl:value-of select="sum(catalog/cd[artist='Bob Dylan' and not(extra/tests/test[contains(., 'CD')])]/price)"/>


非常感谢,@Tim C:)但是,我对“.”部分感到困惑,所以我将对此进行研究。
表示上下文节点,在本例中,它是应用条件的
test
节点。
<xsl:value-of select="sum(catalog/cd[artist='Bob Dylan' and extra[not(tests/test[contains(., 'CD')])]]/price)"/>
<xsl:value-of select="sum(catalog/cd[artist='Bob Dylan' and not(extra/tests/test[contains(., 'CD')])]/price)"/>