How do I retrieve a sibling by tag name in XSLT?

前端 未结 3 1511
无人共我
无人共我 2021-01-15 17:22

I am having an issue with the following, I need the ID to be of each promotiom:

Here is my XML:

 
      
        &         


        
相关标签:
3条回答
  • 2021-01-15 17:50

    The correct XPath in this situation is:

    <asp:LinkButton ID ="{../ID}" onclick="LinkClicked">
    

    Since you are in <Title> context within the <xsl:for-each>, you must go up one level and fetch the <ID> from there. Your try

    /Promotions/Promotion[Category=$category]/ID
    

    fetches all <Promotion>s of a certain category and takes the first ID from the bunch, which is the same every time, naturally.

    0 讨论(0)
  • 2021-01-15 18:00

    Just change

    <asp:LinkButton ID ="{/Promotions/Promotion[Category=$category]/ID}" onclick="LinkClicked">
    

    to

    <asp:LinkButton ID ="{../ID}" onclick="LinkClicked">
    
    0 讨论(0)
  • 2021-01-15 18:06

    Try something like position()=1 in your XSLT to select the first occurrence.

    0 讨论(0)
提交回复
热议问题