A sequence of more than one item is not allowed

Here should go questions about transforming XML with XSLT and FOP.
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

A sequence of more than one item is not allowed

Post 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
tavy
Posts: 365
Joined: Thu Jul 01, 2004 12:29 pm

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

Post 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
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
DanOvergaard
Posts: 22
Joined: Thu Jan 07, 2021 10:44 am

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

Post by DanOvergaard »

Thanks :-)
Post Reply