我正在使用 XSLT 将 XML 转换为 HTML。目前我正试图弄清楚如何在 XSLT 中创建一个数组变量。
这是我的 XML:
<data>
<ACCOUNTS elem="0">
<ACCOUNT_NO>12345</ACCOUNT_NO>
</ACCOUNTS>
<ACCOUNTS elem="1">
<ACCOUNT_NO>67890</ACCOUNT_NO>
</ACCOUNTS>
</data>
这是我试图弄清楚但不工作的 XSLT:
<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>
如何将位置添加到 XML 节点中,以便我能够使用
<xsl:value-of select="$account[@elem=1]" />
请帮助我,如果有任何疑虑,请告诉我。谢谢。
更新 :
我的完整 XSLT 代码:
<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>
当我编译我得到这个错误:
JAXPSAXProcessorInvoker - Error checking type of the expression 'FilterParentPath(variable-ref(accounts/result-tree), step("child", 40, pred(=(step("attribute", 18), literal-expr(0)))))'.