Reputation: 4739
I'm having a template which should only match the element PRA
if it contains a <PRA.3>
having the value 101, 103 or 104. My input looks like this:
<XML>
<PRA>
<PRA.3>101</PRA.3>
<PRA.6>654</PRA.6>
</PRA>
<PRA>
<!-- does not match -->
<PRA.3>999</PRA.3>
<PRA.6>654</PRA.6>
</PRA>
</XML>
The XSLT which works well:
<xsl:template match="PRA[PRA.3='101' or PRA.3='103' or PRA.3='104']">
<!-- does match if PRA.3 equals 101,103,104 -->
</xsl:template>
This works well, but the values 101, 103 and 104 will appear in many more templates and can change.
Is it possible to add these values to a list and then make a contains? Here a sample code I'd like to use:
<MYARRAY>101,102,104</MYARRAY>
<xsl:template match="PRA[MYARRAY.contains(PRA.3/text())]">
</xsl:template>
Upvotes: 3
Views: 6353
Reputation: 1645
In XSLT 2.0 what you want to do is actually rather simple and does not need contains or index-of:
<xsl:variable name="myArray" select="('101','102','104')"/>
<xsl:template match="PRA[PRA.3=$myArray]">
</xsl:template>
This will be sufficient.
Upvotes: 4