xsl-list
[Top] [All Lists]

recursive call of template - how to find parents

2003-11-05 01:55:56
Hello,

I go recursively through a template and print the names of the xml-elements. That works fine (thanks for your help in this newsgroup). But now I need to output another attribute with every element, and I need to output this attribute also from all its parents. How can I find out if there´s still a parent left? I give you an example of my xml-File my xslt-code and the desired output.

Thanks a lot


############# The xml - File #############
<topic name="point1" filename="asdf">
  <topic name="subpoint1" filename="asdf1">
      <topic name="subsubpoint1" filename="asdf2">
          <topic name="subsubsubpoint1" filename="asdf3">
          </topic>
      </topic>
  </topic>
  <topic name="subpoint2" filename="asdf4">
  </topic>
</topic>
<topic name="point2" filename="asdf5">
</topic>
<topic name="point3" filename="asdf6">
</topic>
<topic name="point4" filename="asdf7">
</topic>


############## the xsl template #################

   <xsl:template name="sitemap">
       <ul>
           <xsl:for-each select="//homepage/topic">
               <li>
                   <xsl:value-of select="."/>
               </li>
               <ul>
                   <xsl:apply-templates select="topic"/>
               </ul>
           </xsl:for-each>
       </ul>
   </xsl:template>
   <xsl:template match="topic">
       <li>
           <xsl:value-of select="."/>
           <xsl:if test="topic">
               <ul>
                   <xsl:apply-templates select="topic"/>
               </ul>
           </xsl:if>
       </li>
   </xsl:template>


##################### the desired output ###################

<ul xmlns="">
   <li>
       <a href="asdf">point1
       </a>
       <ul><li>
                   <a href="asdf/asdf1">
                       subpoint1
                           <ul><li>
<a href="asdf/asdf1/asdf2">subsubpoint1</li>
...... and so on.

So you see, the the <a href=..... is the problem. How can I go up in the recusively called template and always add the filename attribute, starting from the uppper mostt topic element?

So if I´m in subsubsubpoint, I´d like to have the fileanmes beginning from the uppermost topic element:
<a href=asdf/asdf1/asdf2/asdf3>

Thanks a lot Michael



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>