I'm trying to transform my XML so I can easily convert it to JSON in a sap integration process. I'm getting a stylesheet compilation error and I cant figure out why. Here is my XML:
<groups>
<UserGroup>
<integrationKey>xxa</integrationKey>
<uid>001</uid>]
</UserGroup>
<UserGroup>
<integrationKey>xxb</integrationKey>
<uid>002</uid>
</UserGroup>
</groups>
Here is my 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>
I get an error even when I try only declare the accumulator. Here is the error text:
[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
I have tried changing the pattern to things like //groups/UserGroup
etc but nothing seems to work. I've tried limiting the XSLT to just:
<?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>
Still erroring. What should I do?
You need to declare the schema namespace for the xs
prefix that is used for the integer type declaration:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
Either add to the xsl:accumulator
element or above on the xsl:stylesheet
element.