Hi, Kai,

The following stylesheet, applied to the following XML (an extension of 
your example), generates the same tree view as used by the Acrobat Reader 
(at least in version 7):

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>

  <xsl:template match="objects">
    <html>
      <head>
        <title>Test</title>
      </head>
      <style>
        &lt;!--
          td {font-family:monospace}
        --&gt;
      </style>
      <body>
        <table>
          <xsl:apply-templates/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="object">
    <tr>
      <td>
        <xsl:for-each select="ancestor::object[not(position()=last())]">
          <xsl:choose>
            <xsl:when test="generate-id(.)=generate-id(../*[last()])">
              &#160;&#160;
            </xsl:when>
            <xsl:otherwise>
              |&#160;
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
        <xsl:choose>
          <xsl:when test="generate-id(.)=generate-id(../*[last()])">
            <xsl:if test="..[not(name()='objects')]">&#160;-</xsl:if>
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:otherwise>
            |-<xsl:value-of select="@id"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates/>
      </td>
    </tr>
  </xsl:template>

  <xsl:template match="relation">
    <xsl:apply-templates/>
  </xsl:template>

</xsl:stylesheet>

XML:
<objects>
  <object Level="0" id="01">
    <relation Level="0">
       <object Level="1" id="11">
         <relation Level="1">
           <object Level="2" id="21">
             <relation Level="2">
               <object Level="3" id="31"/>
               <object Level="3" id="32"/>
             </relation>
           </object>
           <object Level="2" id="22">
             <relation Level="2">
               <object Level="3" id="33">
                 <relation Level="3">
                   <object Level="4" id="41"/>
                   <object Level="4" id="42"/>
                 </relation>
               </object>
               <object Level="3" id="34">
                 <relation Level="3">
                   <object Level="4" id="43"/>
                   <object Level="4" id="44"/>
                 </relation>
               </object>
             </relation>
           </object>
           <object Level="2" id="23">
             <relation level="2">
               <object Level="3" id="35"/>
               <object Level="3" id="36"/>
             </relation>
           </object>
         </relation>
       </object>
    </relation>
  </object>
</objects>

Note that the relation elements and Level attributes are unnecessary. If 
you have control over the application that generates the XML, you could 
eliminate them. In that case you could alse eliminate the match="relation" 
template in the XSL.

If you want a line down the left-most edge, I'll have to leave that to 
you. I have run out of the time that I can spend on someone else's 
project. I did enjoy having something different to work on, though.

Thanks.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Kai Hackemesser" <[EMAIL PROTECTED]> 
02/21/2005 11:45 AM
Please respond to
[EMAIL PROTECTED]


To
[EMAIL PROTECTED]
cc

Subject
Re: XSLT Question






Hi J,

Partly you are right, with your test I can tell what image I need for the
current level of the tree, but I can't see how to retrieve the required
images from lower levels. the test you described needs to be done for 
every
element up to level 0. It's not just the Indent which I want to show, but
also some lines and branches, depending from the structure. Like the 
folder
tree in an windows explorer window. 

Ciao!
Kai

> Hi, Kai,
> 
> I don't think you need to call a template for that. You can test for the 

> characteristics of the  node from within the matching template and get 
the
> image you need.
> 
> Several xsl:when statements within an xsl:choose block should let you 
> figure out which images to use when. For example, <xsl:when 
> test="generate-id(.)=generate-id(../*[last()])"> will tell you whether 
the
> current node is the last child node of its parent. Also, to indent 
> properly, you can read the Level attribute and put the appropriate 
number 
> of indentation objects (blank table cells, spaces, whatever you use) 
> before the image.
> 
> J

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to