I am using XSLT to transform XML to HTML. Currently i am trying to figured out how can i make an array variable in XSLT.
This is my XML :
<data>
<ACCOUNTS elem="0">
<ACCOUNT_NO>12345</ACCOUNT_NO>
</ACCOUNTS>
<ACCOUNTS elem="1">
<ACCOUNT_NO>67890</ACCOUNT_NO>
</ACCOUNTS>
</data>
This is my the XSLT that i try to figured out but is not working :
<xsl:variable name="accounts">
<xsl:for-each select="data/ACCOUNTS">
<child elem="<xsl:value-of select='position()' />"><xsl:value-of select="ACCOUNT_NO" /></child>
</xsl:for-each>
</xsl:variable>
How can i add the position into the XML node so that i'm able to display it out by using
<xsl:value-of select="$account[@elem=1]" />
Please help me and let me know if got any concern. Thanks.
UPDATED :
My full XSLT code :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
<xsl:variable name="accounts">
<xsl:for-each select="data/ACCOUNTS">
<child elem="{@elem}"><xsl:value-of select="ACCOUNT_NO" /></child>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<html>
<head><title>testing</title></head>
<body>
<xsl:value-of select="$accounts/child[@elem='0']" />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And when i compile i get this error :
JAXPSAXProcessorInvoker - Error checking type of the expression 'FilterParentPath(variable-ref(accounts/result-tree), step("child", 40, pred(=(step("attribute", 18), literal-expr(0)))))'.