Having a XML-structure like this:
<ContextDoc>
<PurchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<OrderForms>
<OrderForm>
<Shipments>
<Shipment>
...
<ShippingMethodId>17995798-a2cc-43ad-81e8-bb932f6827e4</ShippingMethodId>
...
</Shipment>
<Shipment>
...
<ShippingMethodId>11223344-a2cc-11bc-25a7-aa345f6827e6</ShippingMethodId>
...
</Shipment>
</Shipments>
<LineItems>
<LineItem>
...
<ShippingMethodId>17995798-a2cc-43ad-81e8-bb932f6827e4</ShippingMethodId>
...
</LineItem>
<LineItem>
...
<ShippingMethodId>17995798-a2cc-43ad-81e8-bb932f6827e4</ShippingMethodId>
...
</LineItem>
<LineItem>
...
<ShippingMethodId>11223344-a2cc-11bc-25a7-aa345f6827e6</ShippingMethodId>
...
</LineItem>
</LineItems>
</OrderForm>
</OrderForms>
</PurchaseOrder>
</ContextDoc>
From the template matching each Shipment node I want to loop the LineItems with the current ShippingMethodId. Like so:
<xsl:template match="Shipment">
<xsl:for-each select="//LineItems/LineItem[ShippingMethodId=./ShippingMethodId]">
<xsl:call-template name="LineItem">
</xsl:call-template>
</xsl:for-each>
</xsl:Template>
But that gives me all LineItems under each Shipment. What is the correct way to call the template for the specific LineItem nodes?
use
current()to point to the context outside the loop. The.inside the loop points to the context of the current element of the lopp. Like this:also, it feels like you can do all you need with “matching” and without calling out templates like functions. Give us a little more idea about what you’re trying to accomplish and we will likely recommend a more ideomatic way to get there. For example, if you need to group by those
ShippingMethodIds you can use the Muenchian method.