Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

Get first occurrence of XSLT stylesheet

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'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...