I have XSLT:
<xsl:template match="/">
<!--<FLC_OKVEDCODE>-->
<xsl:variable name="valArray" select="//NodeA | //NodeB | //NodeC"/>
<xsl:variable name="valResArray">
<result_value>TextA</result_value>
<result_value>TextB</result_value>
<result_value>TextC</result_value>
</xsl:variable>
<xsl:variable name="resArray" select="document('')//xsl:variable[@name= 'valResArray']/*"></xsl:variable>
<xsl:for-each select="$valArray">
<xsl:if test="string-length(normalize-space(text())) = 0">
<ERROR>
<Err1><xsl:value-of select="position()"></xsl:value-of></Err1>
<Err2><xsl:value-of select="$resArray[1]"></xsl:value-of></Err2>
<Err3><xsl:value-of select="$resArray[2]"></xsl:value-of></Err3>
<Err4><xsl:value-of select="$resArray[3]"></xsl:value-of></Err4>
<Err5><xsl:value-of select="$resArray[position()]"></xsl:value-of></Err5>
</ERROR>
</xsl:if>
</xsl:for-each>
<!--</FLC_>-->
</xsl:template>
It have to check NodeA, NodeB and NodeC if they are empty - create error XML. In my test NodeB is empty, but result is:
<ERROR>
<Err1>2</Err1>
<Err2>TextA</Err2>
<Err3>TextB</Err3>
<Err4>TextC</Err4>
<Err5>TextA</Err5>
</ERROR>
Why Err5 is TextA, if position() return 2 and $resArray[2] (printed at ) is TextB??