ThissectiondescribesthemethodyoucanusetoprocessmultiplenodesofanXMLinstancedocumentandhavetheresult
mappedasasinglevaluetoatargetitem.Thefilesusedinthisexampleareavailableinthe...\MapForceExamples\Tutorial\
folderandconsistsof:
Summingnodes.mfd
input.xml
input.xsdandoutput.xsd
Summingnodes.xslt
mappingfile
inputXMLfile
sourceandtargetschemafiles
xsltfilecontaininganamedtemplatetosumthe
individualnodes
Therearetwoseparatemethodsofcreatingandusingaggregatefunctions:
UsingtheaggregatefunctionsavailableinthecorelibraryoftheLibrarypane
UsingaNamedTemplate.
Aggregatefunctionslibrary
DependingontheXSLTlibraryyouselect,XSLT1orXSLT2,differentaggregatefunctionsareavailableinthecorelibrary.
XSLT1supportscountandsum,whileXSLT2supportsavg,count,max,min,stringjoinandsum.
Dragtheaggregatefunctionthatyouusefromthelibraryintothemappingareaandconnectthesourceandtarget
componentsasshowninthescreenshotbelow.
Formoreinformationonthistypeofaggregatefunction,pleasealsoseeAggregatefunctions.
AggregatefunctionNamedtemplate
ThescreenshotbelowshowstheXMLinputfile.TheaimoftheexampleistosumthePricefieldsofanynumberof
products,inthiscaseproductsAandB.
ThescreenshotbelowshowstheXSLTstylesheetwhichusesthenamedtemplate"Total"andasingleparameter"string".
Whatthetemplatedoes,isworkthroughtheXMLinputfileandsumallthevaluesobtainedbytheXPathexpression
/Product/Price,inthedocument.
1. ClicktheAdd/RemoveLibrariesbutton,andselecttheLibrariestaboftheOptionsdialogbox.
2. ClicktheAddbuttonandselecttheSummingnodes.xsltfilefromthe
<Documents>\Altova\MapForce2016\MapForceExamples\folder.
3. DragintheTotalfunctionfromthenewlycreatedSummingnodeslibraryandcreatethemappingsasshownbelow.
4. ClicktheOutputtabtopreviewthemappingresult.
ThetwoPricefieldsofbothproductshavebeenaddedandplacedintotheTotalfield.
TosumthenodesinXSLT2.0:
Changethestylesheetdeclarationinthetemplateto...version="2.0".
2016AltovaGmbH