XSL Template Question (Layout)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GabeGGG
    New Member
    • Mar 2010
    • 17

    XSL Template Question (Layout)

    Does anyone know how I can get the horizontal template boxes to line up? The Network Interface and the IP Address boxes are within a different node so they show up below the Exchange Servers, Replication Required, and Setup Required boxes. (See picture for details). My guess it has something to do with the way I’m using the for-each select parameter.

    Below is my XSL StyleSheet. (I’m using XML version 1.0 for my XML document).

    Code:
    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
      <html>
       <body>
         <body bgcolor="Silver">
       </body>
         <h2>Exchange Server Information</h2>
         <table border="3"> 
          <tr bgcolor="yellow">
          	<th>Exchange Servers</th>
            <th>Replication Required</th>
            <th>Setup Required</th>
            <th>Network Interface</th>
            <th>IP Address</th>
          </tr>	
          <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|
                                DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
                                DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']|    
     
                                DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.98.16']| 
                                DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='157.54.61.141']| 
                                DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='10.31.127.204']"> 
          <tr>
               
               <td><xsl:value-of select="@Fqdn"/></td>
               <td><xsl:value-of select="@RequiresReplication"/></td>
               <td><xsl:value-of select="@RequiresSetup"/></td>
               <td><xsl:value-of select="@InterfaceSide"/></td>
               <td><xsl:value-of select="@IPAddress"/></td>
          </tr>
          </xsl:for-each>
        </table>
       </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
    Attached Files
    Last edited by Dormilich; Apr 6 '10, 04:04 AM. Reason: Please use [code] tags when posting code
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    The best way I can think of to do this would be:
    Code:
          <xsl:apply-templates select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com'|
    DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
    DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']"/>
    
    -- template outside the main template:
    <xsl:template match="Cluster">
          <tr> 
               <td><xsl:value-of select="@Fqdn"/></td> 
               <td><xsl:value-of select="@RequiresReplication"/></td> 
               <td><xsl:value-of select="@RequiresSetup"/></td> 
               <td><xsl:value-of select="Machine/NetInterface/@InterfaceSide"/></td> 
               <td><xsl:value-of select="Machine/NetInterface/@IPAddress"/></td> 
          </tr> 
          <xsl:for-each select="Machine/NetInterface[position &gt; 1]">
            <tr>
               <td/><!--@Fqdn--> 
               <td/><!--@RequiresReplication-->
               <td/><!--@RequiresSetup--> 
               <td><xsl:value-of select="@InterfaceSide"/></td> 
               <td><xsl:value-of select="@IPAddress"/></td> 
            </tr>
          </xsl:for-each>
    </xsl:template>

    Comment

    • GabeGGG
      New Member
      • Mar 2010
      • 17

      #3
      Thanks, but I'm not sure how I would add your code to my below stylesheet. Can you add your code to my style sheet below so that I can get an idea?

      Code:
      <?xml version='1.0'?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
        <html>
         <body>
           <body bgcolor="Silver">
         </body>
           <h2>Exchange Server Information</h2>
           <table border="3"> 
            <tr bgcolor="yellow">
            	<th>Exchange Servers</th>
              <th>Replication Required</th>
              <th>Setup Required</th>
              <th>Network Interface</th>
              <th>IP Address</th>
            </tr>	
            <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']|    
       
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='1.1.1.1']| 
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='2.2.2.2']| 
                                  DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster/Machine/NetInterface[@IPAddress='3.3.3.3']"> 
            <tr>
                 
                 <td><xsl:value-of select="@Fqdn"/></td>
                 <td><xsl:value-of select="@RequiresReplication"/></td>
                 <td><xsl:value-of select="@RequiresSetup"/></td>
                 <td><xsl:value-of select="@InterfaceSide"/></td>
                 <td><xsl:value-of select="@IPAddress"/></td>
            </tr>
            </xsl:for-each>
          </table>
         </body>
        </html>
      </xsl:template>
      </xsl:stylesheet>

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        from the for-each:
        Code:
        ...
        <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|
        DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|
        DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']">
        <tr>  
                   <td><xsl:value-of select="@Fqdn"/></td>  
                   <td><xsl:value-of select="@RequiresReplication"/></td>  
                   <td><xsl:value-of select="@RequiresSetup"/></td>  
                   <td><xsl:value-of select="Machine/NetInterface/@InterfaceSide"/></td>  
                   <td><xsl:value-of select="Machine/NetInterface/@IPAddress"/></td>  
              </tr>  
              <xsl:for-each select="Machine/NetInterface[position &gt; 1]"> 
                <tr> 
                   <td/><!--@Fqdn-->  
                   <td/><!--@RequiresReplication--> 
                   <td/><!--@RequiresSetup-->  
                   <td><xsl:value-of select="@InterfaceSide"/></td>  
                   <td><xsl:value-of select="@IPAddress"/></td>  
                </tr> 
              </xsl:for-each> 
            </table> 
        ...
        Notice most of the Machine/NetInterface handling is dealt within the nested for-each loop
        I guess there's no real need for an extra template if the code is this short.

        Comment

        • GabeGGG
          New Member
          • Mar 2010
          • 17

          #5
          I get the attached error. I have a feeling my styleesheet is not correct. What do you think?

          Code:
          <?xml version='1.0'?>
          <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
          <xsl:template match="/">
            <html>
             <body>
               <body bgcolor="Silver">
             </body>
               <h2>Exchange Server Information</h2>
               <table border="3"> 
                <tr bgcolor="yellow">
                	<th>Exchange Servers</th>
                  <th>Replication Required</th>
                  <th>Setup Required</th>
                  <th>Network Interface</th>
                  <th>IP Address</th>
                </tr>	
             <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']| 
          DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']| 
          DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']"> 
          <tr>   
                     <td><xsl:value-of select="@Fqdn"/></td>   
                     <td><xsl:value-of select="@RequiresReplication"/></td>   
                     <td><xsl:value-of select="@RequiresSetup"/></td>   
                     <td><xsl:value-of select="Machine/NetInterface/@InterfaceSide"/></td>   
                     <td><xsl:value-of select="Machine/NetInterface/@IPAddress"/></td>   
                </tr>   
                <xsl:for-each select="Machine/NetInterface[position &gt; 1]">  
                  <tr>  
                     <td/><!--@Fqdn-->   
                     <td/><!--@RequiresReplication-->  
                     <td/><!--@RequiresSetup-->   
                     <td><xsl:value-of select="@InterfaceSide"/></td>   
                     <td><xsl:value-of select="@IPAddress"/></td>   
                  </tr>  
                </xsl:for-each>  
              </table>  
             </body>
            </html>
          </xsl:template>
          </xsl:stylesheet>
          Attached Files

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            there’s one closing </xsl:for-each> missing (started at line #18)

            Comment

            • GabeGGG
              New Member
              • Mar 2010
              • 17

              #7
              That did it!!!!

              Code:
              <?xml version='1.0'?> 
              <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> 
              <xsl:template match="/"> 
                <html> 
                 <body> 
                   <body bgcolor="Silver"> 
                 </body> 
                   <h2>Exchange Server Information</h2> 
                   <table border="3">  
                    <tr bgcolor="yellow"> 
                        <th>Exchange Servers</th> 
                      <th>Replication Required</th> 
                      <th>Setup Required</th> 
                      <th>Network Interface</th> 
                      <th>IP Address</th> 
                    </tr>     
                 <xsl:for-each select="DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='exch-dc-08.contoso.microsoft.com']|  
                                       DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='tk5ucdfpp01.contoso.microsoft.com']|  
                                       DocItemSet/DocItem/Data/AnchoredXml/Dictionary/Item/Value/Topology/Clusters/Cluster[@Fqdn='b43ucdfms01.contoso.microsoft.com']">  
              <tr>    
                         <td><xsl:value-of select="@Fqdn"/></td>    
                         <td><xsl:value-of select="@RequiresReplication"/></td>    
                         <td><xsl:value-of select="@RequiresSetup"/></td>    
                         <td><xsl:value-of select="Machine/NetInterface/@InterfaceSide"/></td>    
                         <td><xsl:value-of select="Machine/NetInterface/@IPAddress"/></td>    
                    </tr>  
              </xsl:for-each>  
                    <xsl:for-each select="Machine/NetInterface[position &gt; 1]">   
                      <tr>   
                         <td/><!--@Fqdn-->    
                         <td/><!--@RequiresReplication-->   
                         <td/><!--@RequiresSetup-->    
                         <td><xsl:value-of select="@InterfaceSide"/></td>    
                         <td><xsl:value-of select="@IPAddress"/></td>    
                      </tr>   
                    </xsl:for-each>   
                  </table>   
                 </body> 
                </html> 
              </xsl:template> 
              </xsl:stylesheet>

              Comment

              Working...