Using the code below, how do I access the current item in the loop without specifying $array[1]?
<xsl:variable name="array" as="element()*">
<item>https://www.example.com/_resources/data/blogs.xml</item> <!--item 1-->
<item>https://www.example.com/_resources/data/blogs2.xml</item> <!--item 2-->
</xsl:variable>
<xsl:for-each select="$array/item">
<xsl:apply-templates select="document($array[1])/hero-image/img" /><!--How do we access value of current item without specifying $array[1]) -->
</xsl:for-each>
Firstly, the variable
$array
holds a sequence ofitem
elements, and you want to iterate over these elements, not over their children. You have written$array/item
, which is short for$array/child::item
, which selects the children of the elements in the array, not the elements themselves.Secondly, you refer to the current item as
.
. So you would want:But that can be abbreviated to
Note: you are using XSLT 2.0+ here, and it's best to mention that in the question (or simply add the relevant tag, which I shall do for you).