Working on a xslt 1.0 stylesheet for mapping of an address service. I have lookup up some of the examples for the Muenchian method for grouping in xslt 1.0, but i still am confused on the xsl:key and nested xsl:for-each loops.
I am only concerned with the InputAddress
node-set. There may be multiple (but not always) InputAddress
nodesets as part of the parent ValidateRequest
node so i need to loop thru all iterations of InputAddress
and then perform the mapping to the pertinent elements.
source xml
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:v1="blah" xmlns:v3="blah2">
<soap:Header/>
<soap:Body>
<v1:validate>
<ValidateRequest>
<!--One or more repetitions:-->
<InputAddress>
<v3:City>Redmond</v3:City>
<v3:Territory>
<v3:Name>Washington</v3:Name>
<FIPSStateAlphaCode>WA</FIPSStateAlphaCode>
</v3:Territory>
<v3:PostalCode>98007</v3:PostalCode>
<v3:Country>
<!--Zero or more repetitions:-->
<v3:Name>US</v3:Name>
</v3:Country>
<v3:FullAddress>123 main street</v3:FullAddress>
<v3:FullAddress>Ste 200</v3:FullAddress>
</InputAddress>
<InputAddress>
<v3:City>Seattle</v3:City>
<v3:Territory>
<v3:Name>Washington</v3:Name>
<FIPSStateAlphaCode>WA</FIPSStateAlphaCode>
</v3:Territory>
<v3:PostalCode>98103</v3:PostalCode>
<v3:Country>
<!--Zero or more repetitions:-->
<v3:Name>US</v3:Name>
</v3:Country>
<v3:FullAddress>987 1st street</v3:FullAddress>
</InputAddress>
</ValidateRequest>
</v1:validate>
</soap:Body>
expected result
<soap:Body>
<wsdl:WS_MDM_Address_ValidationRequest>
<wsdl:WS_MDM_Address_ValidationRequestElement>
<wsdl:Address_Line1>123 main street</wsdl:Address_Line1>
<wsdl:Address_Line2>Ste 200</wsdl:Address_Line2>
<wsdl:City>Redmond</wsdl:City>
<wsdl:State>WA</wsdl:State>
<wsdl:Postal_Code>98007</wsdl:Postal_Code>
<wsdl:Country>US</wsdl:Country>
</wsdl:WS_MDM_Address_ValidationRequestElement>
<wsdl:WS_MDM_Address_ValidationRequestElement>
<wsdl:Address_Line1>987 1st Street</wsdl:Address_Line1>
<wsdl:City>Seattle</wsdl:City>
<wsdl:State>WA</wsdl:State>
<wsdl:Postal_Code>98103</wsdl:Postal_Code>
<wsdl:Country>US</wsdl:Country>
</wsdl:WS_MDM_Address_ValidationRequestElement>
</wsdl:WS_MDM_Address_ValidationRequest>
</soap:Body>
and my named template snipet after an xsl:choose(not shown):
<xsl:key name="AddressDoctor" match="v3:FullAddress" use="//v3:FullAddress" />
<xsl:variable name="address" select="/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='validate']/ValidateRequest/InputAddress"/>
<xsl:template name="addressdoctor">
<soap:Envelope>
<soap:Header>
<xsl:copy-of select="/*[local-name()='Envelope']/*[local-name()='Header']/*"/>
</soap:Header>
<soap:Body>
<wsdl:WS_MDM_Address_ValidationRequest>
<xsl:for-each select="key('AddressDoctor', '.')">
<wsdl:WS_MDM_Address_ValidationRequestElement>
<xsl:for-each select="[not($FullAddress = preceding::text()=$FullAddress)]">
<xsl:element name="wsdl:{concat('Address_Line',position())}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
<wsdl:City>
<xsl:for-each select="$address/*[local-name()='City']">
<xsl:value-of select="$address/*[local-name()='City']"/>
</xsl:for-each>
</wsdl:City>
<wsdl:State>
<xsl:value-of select="$address/*[local-name()='Territory']/*[local-name()='FIPSStateAlphaCode']"/>
</wsdl:State>
<wsdl:Postal_Code>
<xsl:value-of select="$address/*[local-name()='PostalCode']"/>
</wsdl:Postal_Code>
<wsdl:Country>
<xsl:value-of select="$address/*[local-name()='Country']/*[local-name()='Name']"/>
</wsdl:Country>
</wsdl:WS_MDM_Address_ValidationRequestElement>
</xsl:for-each>
</wsdl:WS_MDM_Address_ValidationRequest>
</soap:Body>
</soap:Envelope>
</xsl:template>
v3:FullAddress
elements? Based on the example input you gave I don't see why you need a grouping function. – Matthew Greenv3:FullAddress
elements, but i mainly want to keep thewsdl:WS_MDM_Address_ValidationRequestElement
nodeset together as it can have multiple iterations, before sending the request to the SP. If i just run afor-each
on each node, i get the value of each node, in each iteration ofwsdl:WS_MDM_Address_ValidationRequestElement
, in other words, the iterations are not unique. – user3225475InputAddress
elements, which are parent 'groups' whose child nodes need to be processed independently and 'grouped' with one another. I look at any other of these grouping based questions with xmlt 1.0 and they involve groups of multiple unique parent nodes, so i don't know how my example could not involve the use of a grouping technique. – user3225475