version 1.0 (using Altova xml spy)
Hi,
I have an xml sheet that contains several repeating nodes that contain different values. I am using a recusive template within my xslt sheet but can't seem to solve my issue. I have used a similar recursive template to evaluate other xml sheets where the functionality works!!!
Basically, in xml there is an element named 'Narrative'
if
its attributes Type='990' and Sequence='2'
OR
its attributes Type='991' and Sequence='2'
I want to concatenate the values (in this instance the result would be 08166)
The XML is
Code:
<?xml version="1.0" encoding="UTF-8"?>
<F4FDeliveryNotification xmlns:fo="http://www.w3.org/1999/XSL/Format" DeliveryNotificationType="Goods Received Note" DocumentType="New" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<F4FDocumentHeader>
....
</F4FDocumentHeader>
<DeliveryNotificationHeader>
<DeliveryReference ReferenceType="Order Number" AssignedBy="Buyer">CB10</DeliveryReference>
<DeliveryReference ReferenceType="Contract Number" AssignedBy="Buyer">D10</DeliveryReference>
<DeliveryReference AssignedBy="Supplier" ReferenceType="Delivery Note Number">D1</DeliveryReference>
<DeliveryDate DateTimeType="Document Created">20090609 09:46:38</DeliveryDate>
<DeliveryDate DateTimeType="Delivery Date">20090520 10:21:01</DeliveryDate>
<TradingPartner PartnerType="Supplier">
<PartnerID PartnerIDType="Assigned by F4F">ME</PartnerID>
</TradingPartner>
<TradingPartner PartnerType="Buyer">
<PartnerID PartnerIDType="Assigned by F4F">YOU</PartnerID>
<Address AddressType="Sold To">
<AddressID AddressIDType="Assigned by Supplier">999</AddressID>
<CompanyName>Acme</CompanyName>
<StreetAddress>War Road</StreetAddress>
<StreetAddress>Blah</StreetAddress>
<CityName>LEEDS</CityName>
<CountyDistrictName>West Yorkshire</CountyDistrictName>
<PostalCode>LL</PostalCode>
</Address>
</TradingPartner>
<Narrative Type="990" Sequence="1">08</Narrative>
<Narrative Type="990" Sequence="2">08</Narrative>
<Narrative Type="991" Sequence="1">164</Narrative>
<Narrative Type="991" Sequence="2">166</Narrative>
</DeliveryNotificationHeader>
<TransportDetails>
....
</TransportDetails>
<DeliveryLine LineNumber="1">
....
</DeliveryLine>
<DeliveryControlTotals>
....
</DeliveryControlTotals>
</F4FDeliveryNotification>
The XSL is
Code:
xsl:call-template name="QtyCalc">
<xsl:with-param name="parIncrement" select="1"/>
<xsl:with-param name="parCount" select="''"/>
</xsl:call-template>
....
<xsl:template name="QtyCalc">
<xsl:param name="parIncrement" select="1"/>
<xsl:param name="parCount" select="''"/>
<xsl:for-each select=".//DeliveryNotificationHeader/Narrative[@node()]">
<!--<xsl:if test="position()=$parIncrement">-->
<xsl:choose>
<xsl:when test="./@Type='990' and ./@Sequence='2'">
<xsl:call-template name="QtyCalc">
<xsl:with-param name="parIncrement" select="$parIncrement + 1"/>
<xsl:with-param name="parCount" select="concat($parCount, .)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="./@Type='991' and ./@Sequence='2'">
<xsl:call-template name="QtyCalc">
<xsl:with-param name="parIncrement" select="$parIncrement + 1"/>
<xsl:with-param name="parCount" select="concat($parCount, .)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="QtyCalc">
<xsl:with-param name="parIncrement" select="$parIncrement + 1"/>
<xsl:with-param name="parCount" select="$parCount"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose><xsl:if test="position()=last()">
<VCTTicketNumber>
<xsl:value-of select="$parCount"/>
</VCTTicketNumber>
</xsl:if>
<!--</xsl:if>-->
</xsl:for-each>
</xsl:template>
In this example, the $parIncrement does NOT increment so I commented-out the
<xsl:if test="position()=$parIncrement"> line.
The
$parCount variable is populated with the current node value but I can't use it to concatenate and the final output is
<VCTTicketNumber xmlns=""/>
whereas it should read
<VCTTicketNumber>08166</VCTTicketNumber>
Please can someone help?
Thanks in advance,