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
String XSL如果测试字符串比较不起作用_String_Xslt_If Statement - Fatal编程技术网

String XSL如果测试字符串比较不起作用

String XSL如果测试字符串比较不起作用,string,xslt,if-statement,String,Xslt,If Statement,我有一些XML,看起来像这样: <region class="TableInfo"> text </region> <region> text </region> 文本 文本 我想编写只保留该部分而不保留class=“TableInfo”的XSL 我尝试了许多不同的方法,包括: <xsl:for-each select="region[class!='TableInfo']"> </xsl:for-each>

我有一些XML,看起来像这样:

<region class="TableInfo">
text
</region>
<region>
text
</region>

文本
文本
我想编写只保留该部分而不保留class=“TableInfo”的XSL

我尝试了许多不同的方法,包括:

<xsl:for-each select="region[class!='TableInfo']">

</xsl:for-each>


及其几种变体。它似乎以某种方式作为值而不是字符串进行计算,因为当我将其设置为!=测试时,所有内容都会被删除,当我将其设置为not()时,不会删除任何内容。有什么帮助吗

谢谢


<xsl:for-each select="region[not(@class='TableInfo')]">

</xsl:for-each>
您忘记了@on
,因此尝试检查类元素而不是属性。很明显,是也无法正常工作,因此我改为使用not()函数


从风格的角度来看,我还建议考虑使用与区域元素匹配的模板,以便您可以使用apply模板而不是for each。

标识规则是您的朋友(当然,您需要指定属性类,而不是“class”元素):


在提供的XML上应用此转换时(将片段包装到单个顶部元素中,使其成为格式良好的XML文档):


文本

@serilain我们了解全部情况了吗?排除只有class=“TableInfo”可以让其他一切通过。那就是。。古怪的在XsltCake中进行了测试,但不起作用。我可以发誓我是在我的代码库中这么做的。编辑,一个工作测试在这里:
<xsl:for-each select="region[not(@class='TableInfo')]">

</xsl:for-each>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="@*|node()">
   <xsl:copy>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
 </xsl:template>

 <xsl:template match="/*"><xsl:apply-templates/></xsl:template>
 <xsl:template match="region[@class='TableInfo']"/>
</xsl:stylesheet>
<region>
text
</region>