是否可以检查字符串数组中是否存在字符串? 我有以下XML:检查字符串数组中是否存在字符串XSL
<?xml version="1.0" encoding="UTF-8"?>
<ItemsArr>
<it attr="DANCHO">
<title>1</title>
</it>
<it attr="DAN">
<title>2</title>
</it>
<it attr="IVANCHO">
<title>3</title>
</it>
<it attr="DRAGANCHO">
<title>4</title>
</it>
<it attr="PETKANCHO">
<title>5</title>
</it>
<keys>
<itemKey>DANCHO</itemKey>
<itemKey>THISISONLYFORTESTING</itemKey>
</keys>
</ItemsArr>
而下面的XSL转换:
<?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">
<xsl:variable name="items" select="ItemsArr/keys/itemKey"/>
<xsl:for-each select="/ItemsArr/it[contains($items,@attr)]">
<tr>
<td><xsl:value-of select="@attr"/></td>
<td><xsl:value-of select="title"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我想所有的按键(ItemsArr /键)存放在数组($ items),然后迭代它的值,这些值存在于$ items数组中。 请注意,有了上述数据,它们都被选中。 如果两个键被交换(DANCHO和THISISONLYFORTESTING),则不会选择任何内容。
这正是我需要的!愚蠢的我......我是XSL的新手,你们帮了我很多。我会坚持你提供的第一个解决方案。 – 2015-01-21 09:01:28