Parent Node Data Within Child For Each Loop

Last post 07-01-2009 7:47 AM by ang_bain. 3 replies.

Sort Posts:

  • Parent Node Data Within Child For Each Loop

    07-01-2009, 6:28 AM
    • Member
      1 point Member
    • ang_bain
    • Member since 07-01-2009, 6:11 AM
    • Posts 2

    Hi hope someone can help...I have to flatten my data so i can insert it into my database...i have a for each loop within my xslt...all works fine...but i need to include data within that loop which sits further up the tree...i can't seem to get this to work...any help would be appreciated...eg of prob below: Im trying to get the top three elements to work inside the for each...i was trying to use a call template but just got tangled up...

     <xsl:template match="RouterList/Router">
            <Supplier><xsl:value-of select="Supplier"/></Supplier>
            <Complete><xsl:value-of select="Complete"/></Complete>
           <GroupID><xsl:value-of select="GroupList/Group/Id" /></GroupID>


               <xsl:for-each select="GroupList/Group/OutwardList/Outward">
              <data2>
                         <ID><xsl:value-of select="Id" /></ID>

             </data2>

    </xsl:for-each>

    </xsl:template>

    Filed under: ,
  • Re: Parent Node Data Within Child For Each Loop

    07-01-2009, 7:06 AM

    Can u provide us a sample input xml and sample output xml which u want to generate.???

    Please mark this post as Answer if it is of help to you!

    " You can't do anything about length of life, but sure you can do about depth of life..! "
  • Re: Parent Node Data Within Child For Each Loop

    07-01-2009, 7:30 AM
    Answer

     Well with XPath

    ..

    or

    parent::node()

    gives you the parent node. If you know you are looking for a particular parent element then you can do

    parent::foo

    to select the parent element named 'foo'.

    Then there is the ancestor axis so

    ancestor::foo

    selects any ancestor elements named 'foo'.

    Depending on what you need you can of course also access a grandparent with

    ../..

    or

    parent::foo/parent:bar

     

    If that does not help then you need to show us samples of your XML and tell us which nodes you want to access.

    Martin Honnen --- MVP XML
    My blog
    Filed under: , ,
  • Re: Parent Node Data Within Child For Each Loop

    07-01-2009, 7:47 AM
    • Member
      1 point Member
    • ang_bain
    • Member since 07-01-2009, 6:11 AM
    • Posts 2

     thanks both of u for replying so quickly I had just found using ../ the required amount of times for each node appears to work...Cool

    ang

Page 1 of 1 (4 items)