Source Xml :
<Lot>
<LotDetails>
<GCode>Ship</GCode>
<ProductQuantity>2</ProductQuantity>
</LotDetails
<LotDetails>
<GCode>Reject</GCode>
<ProductQuantity>4</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Gross</GCode>
<ProductQuantity>3</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Acceptable</GCode>
<ProductQuantity>5</ProductQuantity>
</LotDetails>
</Lot>
<Lot>
<LotDetails>
<GCode>Ship</GCode>
<ProductQuantity>2</ProductQuantity>
</LotDetails
<LotDetails>
<GCode>Reject</GCode>
<ProductQuantity>4</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Gross</GCode>
<ProductQuantity>3</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Acceptable1</GCode>
<ProductQuantity>5</ProductQuantity>
</LotDetails>
</Lot>
<LotDetails>
<GCode>Ship1</GCode>
<ProductQuantity>2</ProductQuantity>
</LotDetails
<LotDetails>
<GCode>Reject</GCode>
<ProductQuantity>4</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Gross</GCode>
<ProductQuantity>3</ProductQuantity>
</LotDetails>
<LotDetails>
<GCode>Acceptable1</GCode>
<ProductQuantity>5</ProductQuantity>
</LotDetails>
</Lot>
TargetXml Field :
<Lot><LotQty>5</LotQty></Lot>
<Lot> <LotQty>2</LotQty></Lot>
<Lot><LotQty>3</LotQty> </Lot>
Here the condition to check to map the target field is :
If LotDetails/GCode = "Acceptable" and the corresponding ProductQuantity not (null and zero)
<LotQty> --> 5 [taken from the corresponding ProductQuantity ]
else if LotDetails/GCode = "Ship" and the corresponding ProductQuantity not (null and zero)
<LotQty> --> 2
else if LotDetails/GCode = "Gross" and the corresponding ProductQuantity not (null and zero)
<LotQty> --> 3
else
<LotQty> --> 0
Here the LotQty should happen only once for a particular iteration of <Lot> based on any of the conditions
if any first condition is satisfied then the map LotQTY from the corresponding ProductQuantity ?
When we use for each LotDetails- we get the qty correctly but it produces multiple results for LotQTY inside each loop as below
<Lot>
<LotQty>5</LotQty>
<LotQty>2</LotQty>
<LotQty>3</LotQty>
</Lot>
<Lot>
<LotQty>2</LotQty>
<LotQty>3</LotQty>
</Lot>
<Lot>
<LotQty>3</LotQty>
</Lot>
When i only use IF conditions with out for each the qty is always selected from the first matched condition
<Lot><LotQty>5</LotQty></Lot>
<Lot> <LotQty>5</LotQty></Lot>
<Lot><LotQty>5</LotQty> </Lot
What i need is as below is only one lotQty for each lot based on first satisfied condition with the corresponding qty
<Lot><LotQty>5</LotQty></Lot>
<Lot><LotQty>2</LotQty></Lot>
<Lot><LotQty>3</LotQty></Lot>
Not sure on the template mach usage a being a beginner on xslt usage
如何根據相應的LotDetails/GCode獲取正確的LotDetails/ProductQuantity,並且不使用每個LotDetails/GCode? 任何可以從if動態傳遞滿足條件的方法,並使用LotDetails選擇正確的ProductQuantity或從當前節點中選擇ProductQuantity?XSLT條件在foreach中只發生一次
Please let know xslt experts on the best way to do this ?
您的問題不清楚。請在給定示例中顯示預期的結果,並在必要時添加更多示例。 - FYI,'xsl:for-each'不是一個循環,不能退出或繼續。如果你想要一個結果,不要使用'xsl:for-each'。 –
@Dev,嘗試將整個條件放入if標籤或模板的匹配條件中。否則,如果您因爲某種原因需要for-each,請創建xsl變量並將其用作標誌。一旦顯示了所需的值,將該變量設置爲false以忽略任何其他值。 – derloopkat
感謝您輸入 - 我變化到單個如果與對每個條件 – Dev