I have the following code which I use to get the sum of product values.
<xsl:for-each select="//fn:array[@key= 'Items']/fn:map[*[@key = 'OrderId'][.= $OrderId ] and *[@key = 'Type'][.= 'ServiceRevenue' ] ] ">
<amount>
<xsl:value-of select="fn:map[@key ='Amount']/*[@key = 'Net']" />
</amount>
</xsl:for-each>
I am trying to only calculate the first occurrence where [*[@key = 'OrderId'][.= $OrderId ]
.
I tried the following, but I am still getting all the occurrences:
<xsl:for-each select="//fn:array[@key= 'Items']/fn:map[*[@key = 'OrderId'][.= $OrderId ][0] and *[@key = 'Type'][.= 'ServiceRevenue' ] ] ">
<amount>
<xsl:value-of select="fn:map[@key ='Amount']/*[@key = 'Net']" />
</amount>
</xsl:for-each>
Sample JSON:
[
{
"Items":[
{
"Id":"5b44f410-7034-4972-919d-acac00ead7e9",
"OrderId":"e7791603-ca5f-47c4-9b0c-acac00ead753",
"Type":"ServiceRevenue",
"Amount":{
"Value":25.0,
"Net":25.0,
"Tax":0.0
}
}
]
},
{
"Items":[
{
"Id":"5b44f410-7034-4972-919d-acac00ead7e9",
"OrderId":"e7791603-ca5f-47c4-9b0c-acac00ead753",
"Type":"ServiceRevenue",
"Amount":{
"Value":25.0,
"Net":25.0,
"Tax":0.0
}
}
]
}
]
I only want to calculate the Amount of the first Item occurrence where the OrderId = 'e7791603-ca5f-47c4-9b0c-acac00ead753'
question from:
https://stackoverflow.com/questions/65682182/get-first-occurrence-of-xslt-stylesheet 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…