I have the following source document
<TransportOrder>
<Orders>
<Order>
<OrderSpecification>
<Stops>
<Stop SeqNo="0" StopType="1" StopOrder="0">
<AddressDetails>
<Name>john doe</Name>
<AddressInfos>
<AddressInfo />
</AddressInfos>
<Street>street</Street>
<StreetNo>1</StreetNo>
</AddressDetails>
</Stop>
</Stops>
<OrderText>
<CarrierInstruction>, , , , 1.052</CarrierInstruction>
</OrderText>
</OrderSpecification>
</Order>
<Order>
<OrderSpecification>
<Stops>
<Stop SeqNo="0" StopType="1" StopOrder="0">
<AddressDetails>
<Name>john doe</Name>
<AddressInfos>
<AddressInfo />
</AddressInfos>
<Street>street</Street>
<StreetNo>1</StreetNo>
</AddressDetails>
</Stop>
</Stops>
<OrderText>
<CarrierInstruction>, +, 1, , 1.052</CarrierInstruction>
</OrderText>
</OrderSpecification>
</Order>
<Order>
<OrderSpecification>
<Stops>
<Stop SeqNo="0" StopType="1" StopOrder="0">
<AddressDetails>
<Name>john smith</Name>
<AddressInfos>
<AddressInfo />
</AddressInfos>
<Street>street</Street>
<StreetNo>2</StreetNo>
</AddressDetails>
</Stop>
</Stops>
<OrderText>
<CarrierInstruction>, , , , 1.055</CarrierInstruction>
</OrderText>
</OrderSpecification>
</Order>
<Order>
<OrderSpecification>
<Stops>
<Stop SeqNo="0" StopType="1" StopOrder="0">
<AddressDetails>
<Name>john smith</Name>
<AddressInfos>
<AddressInfo />
</AddressInfos>
<Street>street</Street>
<StreetNo>2</StreetNo>
</AddressDetails>
</Stop>
</Stops>
<OrderText>
<CarrierInstruction>, , , , 1.055</CarrierInstruction>
</OrderText>
</OrderSpecification>
</Order>
</Orders>
</TransportOrder>
and the following stylesheet
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output indent="yes"/>
<xsl:template match="TransportOrder">
<transfer>
<xsl:for-each select="Orders/Order">
<xsl:variable name="mergeId">
<xsl:value-of select="OrderSpecification/Stops/Stop[@StopType='1']/AddressDetails/Street"/>-<xsl:value-of select="OrderSpecification/Stops/Stop[@StopType='1']/AddressDetails/StreetNo"/>-<xsl:value-of select="OrderSpecification/Stops/Stop[@StopType='1']/AddressDetails/Name"/>
</xsl:variable>
<order>
<message>
<messageType>merge</messageType>
</message>
<identification>
<orderNumber><xsl:value-of select="$mergeId"/></orderNumber>
</identification>
</order>
</xsl:for-each>
<xsl:for-each select="Orders/Order[$mergeId=$mergeId]">
<xsl:variable name="weight">
<xsl:value-of select="normalize-space(substring-after(substring-after(substring-after(substring-after(OrderSpecification/OrderText,','),','),','),','))"/>
</xsl:variable>
<xsl:variable name="vehicle">
<xsl:choose>
<xsl:when test="sum($weight[$mergeId=$mergeId])<= 50">truck</xsl:when>
<xsl:otherwise>car</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<order>
<message>
<messageType>update</messageType>
</message>
<identification>
<orderNumber><xsl:value-of select="$mergeId"/></orderNumber>
</identification>
<vehicle>
<vehicleCode><xsl:value-of select="$vehicle"/></vehicleCode>
</vehicle>
</order>
</xsl:for-each>
</transfer>
</xsl:template>
</xsl:stylesheet>
What im trying to accomplish is to take the sum of the weight on each Order from OrderText/carrierInstruction(the substring after the 4 commas, data will be between the commas but removed for privacy and relevancy reasons) where the $mergeId matches and by looking at the weight set different vehicleCodes.
Preferably i would only want to print out the order[messageType='update'] part for the unique mergeId's as well. PS: the 4 Order segments with messagetype merge are correct and needs to be there. the stylesheet is currently broken because the sum must evaluate to a nodeset and im a bit unsure on how to accomplish this. if it is even possible in XLST 1.0(i can only use 1.0 since the software im implementing this into only support 1.0)
my wanted result would be something like this,
<?xml version="1.0"?>
<transfer>
<order>
<message>
<messageType>merge</messageType>
</message>
<identification>
<orderNumber>street-1-john doe</orderNumber>
</identification>
</order>
<order>
<message>
<messageType>merge</messageType>
</message>
<identification>
<orderNumber>street-1-john doe</orderNumber>
</identification>
</order>
<order>
<message>
<messageType>merge</messageType>
</message>
<identification>
<orderNumber>street-2-john smith</orderNumber>
</identification>
</order>
<order>
<message>
<messageType>merge</messageType>
</message>
<identification>
<orderNumber>street-2-john doe</orderNumber>
</identification>
</order>
<order>
<message>
<messageType>update</messageType>
</message>
<identification>
<orderNumber>street-2-john smith</orderNumber>
</identification>
<vehicle>
<vehicleCode>car</vehicleCode>
</vehicle>
</order>
<order>
<message>
<messageType>update</messageType>
</message>
<identification>
<orderNumber>street-1-john doe</orderNumber>
</identification>
<vehicle>
<vehicleCode>car</vehicleCode>
</vehicle>
</order>
</transfer>
it would be acceptable to have 4 order segments with the messagetype update as well the most important part is checking the weight and setting the proper vehicleCode.