Check if string exists in array of strings XSL



Is it possible to check if a string exists in an array of strings in XSL? I have the following XML:



<?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>


And the following XSL transformation:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR">
<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>


I want to store all the keys (ItemsArr/Keys) in an array ($items) and then iterate over the it-s, which attr value exists in the $items array. Note that with the above data, both it are selected. If the two keys are swapped (DANCHO and THISISONLYFORTESTING) then nothing is selected.


No comments:

Post a Comment