Short question:
why my xsl:accumulator-rule
<xsl:when test="substring($msg, $value, string-length(./TagField/@value)) != ./TagField/@value">
doesn't work with Saxon PE 9.9, but works with XSL Professional 2020 sp1. The error reported by Saxon is:
Error evaluating (fn:accumulator-before(...) = fn:accumulator-after(...)) in xsl:when/@test on line 45 column 100 of format.xslt: XPTY0004: An empty sequence is not allowed as the second argument of fn:substring(). Found while atomizing the first operand of '=' In template rule with match="pattern matching node()/element(Q{}MessageFormat)/element(Q{}StructFormat)[(not(attribute::attribute(Q{}repeat))) and child::element(Q{}TagField)]" on line 82 of format.xslt invoked by built-in template rule (shallow-copy) invoked by xsl:apply-templates at file:/D:/issue/pfr-transportevent-v01/config/transformation/xslt/format.xslt#102 at procedure complete-struct on line 101 of format.xslt: invoked by global xsl:variable In template rule with match="/" on line 104 of format.xslt An empty sequence is not allowed as the second argument of fn:substring(). Found while atomizing the first operand of '='
Here is my complete xsl:accumulator
<xsl:accumulator name="position-count" as="xs:integer?" initial-value="1" streamable="no">
<xsl:accumulator-rule match="$MFL/MessageFormat/StructFormat" phase="end">
<xsl:choose>
<xsl:when test="./@repeat = '*' ">
<xsl:choose>
<xsl:when test="substring($msg, $value, string-length(./TagField/@value)) != ./TagField/@value">
<xsl:sequence select="$value"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="repeat" select="count(tokenize(fn:substring($msg, $value) , ./TagField/@value)) - 1"/>
<xsl:sequence select="$value + map:get($groupsize, ./@name) * $repeat"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="substring($msg, $value, string-length(./TagField/@value)) = ./TagField/@value">
<!--<xsl:sequence select="$value + xs:integer(sum(.//FieldFormat/@length)) + string-length(./TagField/@value)"/>-->
<xsl:sequence select="$value + map:get($groupsize, string(./@name))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:accumulator-rule>
</xsl:accumulator>
Backgroud:
I have to solve following problem, the input is plain text with variable length, for example
"H0 EVU_DBSRD PVG Z24 ABF-RF IR 0112019-12-10-14.46.18.553122NJJNNJNM1 80142455360001 M2 10.12.201914:40:00Z1 RABWR1 10.12.2019 10.12.201914:40:00 0000R1 00133807843874880201912103988789201912101530419325346965 000 NN R1 002338078480716 201912101446013716142455 000 NN R1 00324714370125580201912103961427201912101200186865346965 000 NN R1 00433807840438580201912103984329201912101530381256346965 000 NN R1 00524714273013180201912093997400201912090900494682346965 000 NN R1 00637847829609880201912104006488201912101530572232346965 000 NN R1 00737807836474280201912103954824201912101530128369346965 000 NN R1 008338079134858 201912101446013858142455 000 NN R1 00933807849379280201912103979328201912101530334318346965 000 NN R1 01037847829649480201912103990982201912101530433292346965 000 NN R1 011338078414616 201912101446013616142455 000 NN "
( I put the text in quote to keep spaces after last character N)
The expected out is following:
<?xml version="1.0" encoding="UTF-8"?>
<TransportEvent>
<TransportEventHeader>
<NotificationTriggeringOU>EVU_DBSRD</NotificationTriggeringOU>
<NotificationTriggeringIT>PVG</NotificationTriggeringIT>
<NotificationReference>Z</NotificationReference>
<NotificationCode>24</NotificationCode>
<NotificationType>ABF-RF</NotificationType>
<NotificationStatus>I</NotificationStatus>
<NotificationTripType>R</NotificationTripType>
<ProducingRailwayUndertaking/>
<ExternalPartner> </ExternalPartner>
<ActualNumberOfWagons>11</ActualNumberOfWagons>
<ProcessingTime>2019-12-10-14.46.18.553122</ProcessingTime>
<NotificationFunctionalClassification>
<OrderRelevant>N</OrderRelevant>
<TimetableRelevant>J</TimetableRelevant>
<CapacityRelevant>J</CapacityRelevant>
<IntermodalRelevant>N</IntermodalRelevant>
<XrailRelevant>N</XrailRelevant>
<NotificationLocationRelevant>J</NotificationLocationRelevant>
</NotificationFunctionalClassification>
<Reserve>N</Reserve>
</TransportEventHeader>
<NotificationLocation>
<CurrentLocation>
<CurrentLocationRL100/>
<CurrentLocationLocationType/>
<CurrentUICRailAuthorityNumber> 80</CurrentUICRailAuthorityNumber>
<CurrentNetworkLocationNumber>142455</CurrentNetworkLocationNumber>
<CurrentLocationSatelliteNumber>36</CurrentLocationSatelliteNumber>
<CurrentFreightCarLocationNumber>0001</CurrentFreightCarLocationNumber>
</CurrentLocation>
<NextLocation>
<NextLocationRL100/>
<NextLocationLocationType/>
<NextUICRailAuthorityNumber/>
<NextNetworkLocationNumber/>
<NextLocationSatelliteNumber/>
<NextFreightCarLocationNumber/>
</NextLocation>
</NotificationLocation>
<NotificationTime>
<ActualTime>10.12.201914:40:00</ActualTime>
</NotificationTime>
<Trip>
<TripNumber>RABWR1</TripNumber>
<RegionDBNetz/>
<NationalProductionDate>10.12.2019</NationalProductionDate>
<TrainTypeMainNumber/>
<TrainTypeSubNumber/>
<DepartureStationRL100/>
<DepartureStationUICRailAuthority/>
<DepartureStationNetworkLocation/>
<TargetTime>10.12.201914:40:00</TargetTime>
<RelativeTime> 0000</RelativeTime>
</Trip>
<Ordering>
<OrderingPosition>1</OrderingPosition>
<OrderingVehicleNumber>338078438748</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103988789</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530419325346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>2</OrderingPosition>
<OrderingVehicleNumber>338078480716</OrderingVehicleNumber>
<OrderingCommercialOrderKey/>
<OrderingProductionOrderKey>201912101446013716142455</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>3</OrderingPosition>
<OrderingVehicleNumber>247143701255</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103961427</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101200186865346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>4</OrderingPosition>
<OrderingVehicleNumber>338078404385</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103984329</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530381256346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>5</OrderingPosition>
<OrderingVehicleNumber>247142730131</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912093997400</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912090900494682346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>6</OrderingPosition>
<OrderingVehicleNumber>378478296098</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912104006488</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530572232346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>7</OrderingPosition>
<OrderingVehicleNumber>378078364742</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103954824</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530128369346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>8</OrderingPosition>
<OrderingVehicleNumber>338079134858</OrderingVehicleNumber>
<OrderingCommercialOrderKey/>
<OrderingProductionOrderKey>201912101446013858142455</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>9</OrderingPosition>
<OrderingVehicleNumber>338078493792</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103979328</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530334318346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>10</OrderingPosition>
<OrderingVehicleNumber>378478296494</OrderingVehicleNumber>
<OrderingCommercialOrderKey>80201912103990982</OrderingCommercialOrderKey>
<OrderingProductionOrderKey>201912101530433292346965</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
<Ordering>
<OrderingPosition>11</OrderingPosition>
<OrderingVehicleNumber>338078414616</OrderingVehicleNumber>
<OrderingCommercialOrderKey/>
<OrderingProductionOrderKey>201912101446013616142455</OrderingProductionOrderKey>
<OrderingConsignmentNumberID/>
<OrderingTrainGroup>0</OrderingTrainGroup>
<FlagActivation/>
<FlagClosing/>
<FlagCompletion/>
<FlagSuspended/>
<WagonIntermodal>N</WagonIntermodal>
<OderIntermodal>N</OderIntermodal>
<Activation>
<ActivationRL100Location/>
<ActivationLocationLocationType/>
<ActivationUICRailAuthorityLocationNumber/>
<ActivationNetworkLocationNumber/>
<ActivationSatelliteLocationNumber/>
<ActivationFreightCarLocationNumber/>
</Activation>
<Completion>
<CompletionRL100Location/>
<CompletionLocationLocationType/>
<CompletionUICRailAuthorityLocationNumber/>
<CompletionNetworkLocationNumber/>
<CompletionSatelliteLocationNumber/>
<CompletionFreightCarLocationNumber/>
</Completion>
</Ordering>
</TransportEvent>
My XSLT tempalte is working with XML Spy Pro 2020 sp1, however with saxon 9.9 PE I get error with my accumulator in the accumulator-rule.
I know Saxon implementation is strict to W3C XSLT spec, XML Spy Pro usually not always. What did I wrong with my ``accumulator-rule`?
accumulator
to remember the start postion of a group (StructFormat
in the rules.xml) . SomeStructFormat
are optional, some are repeating N times. It depends on if the valueTagField/@value
occues or how many timeTagField/@value
occures. whenfn:accumulator-before
andfn:accumulator-after
, then thisStructFormat
will be skippted. – dingjun<xsl:value-of select="$value"/>
in thexsl:otherwise
to<xsl:sequence select="$value"/>
? – Martin Honnendocument()
function) which seems a little curious. Thexsl:value-of
on line 49 should clearly bexsl:sequence
, but I don't think that's the cause of the error. What happens if you declare the accumulator withas="xs:integer"
rather thanxs:integer?
– Michael Kay