在 XSLT v1.0 中使用结尾 [英] Use ends with in XSLT v1.0
问题描述
我正在尝试编辑当前的 XSLT.我想要的功能是当//code_no"的值以 01 结尾时,我想编辑当前城市位置.目前此功能不存在.我曾尝试使用字符串和子字符串,但它给了我一个错误,说以功能结束不存在.请帮忙
I am trying to edit a current XSLT. The functionality I want is when the value of "//code_no" ends with 01 I want to edit the current city location. Currently this functionality does not exist. I have tried using string and substring but it gives me an error saying ends with functionality does not exist. Please help
来自xml的值是
<code_no>
1870410001
</code_no>
在 xsl 中,当值以 01 结尾时,我想打印这个.
in the xsl, I want to print this when the value ends with 01.
<td align="left" width="33%"><SPAN style="font-size: 12pt; font-family: Arial;">
<a> <b><u><xsl:value-of select="//city"/>, <xsl:value-of select="//state"/>
</u></b></a></SPAN></td>
推荐答案
XPath 1.0 等效于(XPath 2.0)表达式:
ends-with($s, $t)
是:
$t = substring($s, string-length($s) - string-length($t) +1)
您只需将最后一个 XPath 表达式中的 $s
和 $t
分别替换为要测试的字符串,并且待测试的结局.
You need just to substitute $s
and $t
in the last XPath expression with, respectively, the string to be tested, and the ending to be tested.
这是一个完整的例子:
<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="x|y">
<xsl:value-of select="name()"/> ends-with '_01': <xsl:value-of select=
"'_01' = substring(., string-length() - 2)"/>
=============
</xsl:template>
</xsl:stylesheet>
当此转换应用于以下 XML 文档时(问题中没有提供!!!):
when this transformation is applied on the following XML document (none was provided in the question!!!):
<t>
<x>abcd_01</x>
<y>abcd_11</y>
</t>
产生了想要的、正确的结果:
x ends-with '_01': true
=============
y ends-with '_01': false
=============
这篇关于在 XSLT v1.0 中使用结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!