xml 如何在 xsl 中检查字符串相等性不区分大小写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8940695/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check for string equality case insensitive in xsl
提问by AabinGunz
I have a requirement where I need to check DB/@dbtype== 'oracle' (case insensitive). How can I do that?
Here is my code
我有一个要求,我需要检查DB/@dbtype== 'oracle'(不区分大小写)。我怎样才能做到这一点?这是我的代码
<xsl:choose>
<xsl:when test="DB/@dbtype">
<p>
<dd>
<table border="1">
<tbody>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<xsl:if test="DB/@dbtype='ORACLE'">
<xsl:for-each select="DB/oracle_props">
<tr>
<td valign="top" ><xsl:value-of select="@name"/></td>
<td valign="top" ><xsl:value-of select="@value"/></td>
</tr>
</xsl:for-each>
</xsl:if>
</tbody>
</table>
</dd>
</p>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DB"/>
</xsl:otherwise>
</xsl:choose>
I thought of converting it into all lowercase/uppercase and then check accordingly, so I used below
我想把它转换成所有小写/大写,然后相应地检查,所以我在下面使用
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:value-of select="translate(product/@name, $smallcase, $uppercase)"/>
<!--It display in lower case, but how to use this in checking for equality?-->
Please help me out, how to compare String (case insensitive way)
请帮帮我,如何比较字符串(不区分大小写的方式)
回答by Kirill Polishchuk
In the same way:
以同样的方式:
<xsl:if test="translate(DB/@dbtype, $smallcase, $uppercase) = 'ORACLE'">
回答by Dino Fancellu
Well if you're using XSLT 2.0+ then you can use
好吧,如果您使用的是 XSLT 2.0+,那么您可以使用
http://saxonica.com/documentation/functions/intro/lower-case.xml
http://saxonica.com/documentation/functions/intro/lower-case.xml
i.e.
IE
<xsl:if test="lower-case(product/@name)='oracle'">
something
</xsl:if>
回答by Liam Dawson
<xsl:if test="translate(product/@name, $smallcase, $uppercase) = translate('Oracle', $smallcase, $uppercase)">
stuff
</xsl:if>

