A sequence of more than one item is not allowed
Posted: Wed Nov 23, 2022 6:24 am
Hi,
After we have changed from XSLT 1.0 to 2.0 I have encountered a problem with a test that now return “A sequence of more than one item is not allowed as the first argument of starts-with()”
I hope some of you can guide me to the best way to solve the problem.
The XSLT is generated from this schema
Generated XSLT and the test that fails
XML
Note
I know that the test was not working as intended in XSLT 1.0 as code only checks the *first* occurrence (If I understand it correctly
After we have changed from XSLT 1.0 to 2.0 I have encountered a problem with a test that now return “A sequence of more than one item is not allowed as the first argument of starts-with()”
I hope some of you can guide me to the best way to solve the problem.
The XSLT is generated from this schema
Code: Select all
<sch:report test="starts-with(cac:Price/cac:AllowanceCharge/cbc:Amount,'-')">[F-INV335] AllowanceCharge.Amount can not be negative.</sch:report>
Code: Select all
<xsl:if test="cac:Price/cac:AllowanceCharge/starts-with(cbc:Amount,'-')">
<Error>
<xsl:attribute name="context">
<xsl:value-of select="concat(name(parent::*),'/',name())"/>
</xsl:attribute>
<Pattern>starts-with(cac:Price/cac:AllowanceCharge/cbc:Amount,'-')</Pattern>
<Description>[F-INV335] AllowanceCharge.Amount can not be negative</Description>
<Xpath>
<xsl:for-each select="ancestor-or-self::*">/<xsl:value-of select="name()"/>[<xsl:value-of select="count(preceding-sibling::*[name(.)=name(current())])+1"/>]</xsl:for-each>
</Xpath>
</Error>
Code: Select all
<cac:Price>
<cbc:PriceAmount currencyID="DKK">25.00</cbc:PriceAmount>
<cbc:BaseQuantity unitCode="EA">1</cbc:BaseQuantity>
<cbc:OrderableUnitFactorRate>1</cbc:OrderableUnitFactorRate>
<cac:AllowanceCharge>
<cbc:ID>1</cbc:ID>
<cbc:ChargeIndicator>true</cbc:ChargeIndicator>
<cbc:Amount currencyID="DKK">5.00</cbc:Amount>
</cac:AllowanceCharge>
<cac:AllowanceCharge>
<cbc:ID>2</cbc:ID>
<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
<cbc:Amount currencyID="DKK">5.00</cbc:Amount>
</cac:AllowanceCharge>
</cac:Price>
I know that the test was not working as intended in XSLT 1.0 as code only checks the *first* occurrence (If I understand it correctly