我正在尝试转换我的 XML,以便可以在 sap 集成过程中轻松地将其转换为 JSON。我得到一个样式表编译错误,我不知道为什么。这是我的 XML:
<groups>
<UserGroup>
<integrationKey>xxa</integrationKey>
<uid>001</uid>]
</UserGroup>
<UserGroup>
<integrationKey>xxb</integrationKey>
<uid>002</uid>
</UserGroup>
</groups>
这是我的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:accumulator name="UserGroupCounter" as="xs:integer" initial-value="0">
<xsl:accumulator-rule match="//groups" select="0"/>
<xsl:accumulator-rule match="//groups/UserGroup" select="$value + 1"/>
</xsl:accumulator>
<xsl:template match="UserGroup">
<xsl:copy>
<xsl:attribute name="userGroupIndex" select="accumulator-before('UserGroupCounter')"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:mode on-no-match="shallow-copy" use-accumulators="UserGroupCounter"/>
</xsl:stylesheet>
即使我尝试只声明累加器,我也会收到错误消息。这是错误文本:
[CAMEL][IFLOW][EXCEPTION] : org.apache.camel.FailedToCreateRouteException: Failed to create route Process_817351: Route(Process_817351)[[From[direct:Process_817351]] -> [To[o... because of net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
[CAMEL][IFLOW][CAUSE] : Cause: javax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
[CAMEL][IFLOW][CAUSE] : Cause: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
[CAMEL][IFLOW][CAUSE] : Cause: net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation
我曾尝试将模式更改为//groups/UserGroup
等,但似乎没有任何效果。我尝试将 XSLT 限制为:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:accumulator name="UserGroupCounter" as="xs:integer" initial-value="0">
</xsl:accumulator>
还在报错。我该怎么办?