How can I make sure, that xsl:evaluate returns a sequence of nodes, in case the xPath matches multiple nodes.
Suppose the following input.xml
<numlist key="K1">
<numlitm key="K2">C1</numlitm>
<numlitm key="K2">C2</numlitm>
<numlitm key="K3">C3</numlitm>
</numlist>
And the following XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xst="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xs"
version="3.0">
<xsl:variable name="main-doc" select="/"/>
<xsl:template match="/">
<xsl:variable name="var">//*[@key='K2']</xsl:variable>
<xsl:variable name="eval">
<xsl:evaluate xpath="$var" context-item="$main-doc" />
</xsl:variable>
<xsl:copy-of select="$eval"/>
</xsl:template>
</xsl:stylesheet>
The result is
<numlitm key="K2">C1</numlitm>
<numlitm key="K2">C2</numlitm>
I would like the result, stored in eval
, to be a sequence of two elements, so that I can iterate over the two numlitm
via a for-each loop (I need this to construct a key). The issue is that the result seems not to be a node sequence, thus a for-each iteration will yield both numlitm rows, instead of each row in one seperate iteration