how to comapre two xml data in xsl RRS feed

  • Question

  • I have xml data like

            - <Item>
            - <Item>

            <ItemCrPerson>J C</ItemPerson>
            <ItemCrPerson>B J</ItemPerson>

    I am trying to display  each item and than its plan below it.
    Everything is fine. BUT

    I use

    <xsl:for-each select="//ItemList/Item">  to display each item
     and than another nested
     <xsl:for-each select="//ItemPlanList/ItemPlan">
     to display ItemPlan

    This will definitely display all the item plans under each item  but I want the plan only for one particular item being displayed above it.

    So i tried to use a xsl if test condition, but it is not giving me the desired result

    <xsl:if test = "//ItemPlanList/ItemPlan/ItemID =//ItemList/Item/ItemID ">

    But its not giving the desired result.

    How to make it work? how to compare two xml data .

    I know how to compare and xml data to another value like
    < xsl:if test =" //ItemPlanList/ItemPlan/ItemCreation[. = 'Refurbished'] " >

    But here I need to compare "//ItemPlanList/ItemPlan/ItemID =//ItemList/Item/ItemID "
    and only display the particular one

    How to compare and display only the item plan for the item displayed above it

    Thank you

    Friday, August 7, 2009 4:08 PM


  • I think you want

    <xsl:for-each select="//ItemList/Item">
       <xsl:for-each select="//ItemPlanList/ItemPlan[ItemID = current()/ItemID]">

    but you might want to post a well-formed XML sample to start with. Note also that // is expensive, you might want to use an exact path instead e.g. /root/ItemList/Item if there is a root element containing the ItemList elements.
    MVP XML My blog
    Friday, August 7, 2009 4:24 PM