Page 1 of 1

A sequence of more than one item is not allowed

Posted: Wed Nov 23, 2022 6:24 am
by DanOvergaard
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

Code: Select all

<sch:report test="starts-with(cac:Price/cac:AllowanceCharge/cbc:Amount,'-')">[F-INV335] AllowanceCharge.Amount can not be negative.</sch:report>
Generated XSLT and the test that fails

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>
XML

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>
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

Re: A sequence of more than one item is not allowed

Posted: Wed Nov 23, 2022 4:52 pm
by tavy
Hi,

Yes, it seems that for XSLT 1.0 the XPath expression returns the first element

I recommend you to rewrite the rule something like this:

Code: Select all

<sch:rule context="cac:Price/cac:AllowanceCharge/cbc:Amount">
  <sch:report test="starts-with(., '-')">[F-INV335] AllowanceCharge.Amount can not be negative.</sch:report>
</sch:rule>
Best Regards,
Octavian

Re: A sequence of more than one item is not allowed

Posted: Thu Dec 08, 2022 2:46 pm
by DanOvergaard
Thanks :-)