locked
Is it possible to use XSLT to display a nested web.sitemap into a single non-nested table? RRS feed

  • Question

  • User846546683 posted

    Is it possible to use XSLT to display a nested web.sitemap into a single non-nested table?

    Looking around on the web, I found some XSLT code that transforms a web.sitemap file into a nested set of unordered lists (UL).  Converting that into table markup, what I get is a set of nested tables.

    I know I'm "doing it wrong."  Does someone know how to present this as a single table -- not nested?  Is there a way to do this right?

    Thank you

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:map="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" exclude-result-prefixes="map">
      <xsl:output method="xml" encoding="utf-8" indent="yes"/>
      
        <xsl:template name="mapNode" match="map:siteMap">
          <table>
            <xsl:apply-templates/>
          </table>
        </xsl:template>
      
      <xsl:template match="map:siteMapNode">
        <tr>
          <td style="border:thin solid red;">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="@url"/>
              </xsl:attribute>
            <xsl:value-of select="@title"/>
          </a>
    
          <xsl:if test="map:siteMapNode">
            <xsl:call-template name="mapNode"/>
          </xsl:if>
          </td>
          <td style="border:thin solid red;">
            <xsl:value-of select="@description"/>
          </td>
      </tr>
      </xsl:template>
      
    </xsl:stylesheet>

    Tuesday, October 21, 2014 3:53 PM

Answers

  • User846546683 posted

    Yes, I looked at the link before. Notice that the title says "WITHOUT using tables."

    I want my output to BE a table and not a nested unordered list.

    As it turns out someone helped me last night.  Here what worked for me.

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" 
    exclude-result-prefixes="map">
    <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
    <xsl:template match="/map:siteMap">
        <table>
            <xsl:apply-templates select="map:siteMapNode"/>
        </table>
    </xsl:template>
    
    <xsl:template match="map:siteMapNode">
        <tr>
            <td>
                <a href="{@url}"><xsl:value-of select="@title"/></a>
            </td>
            <td>
                <xsl:value-of select="@description"/>
            </td>
        </tr>
        <xsl:apply-templates select="map:siteMapNode"/>
    </xsl:template>
    
    </xsl:stylesheet>



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 22, 2014 9:36 AM

All replies

  • User-1926401737 posted

    Hi HatesSunlight,

    Looking around on the web, I found some XSLT code that transforms a web.sitemap file into a nested set of unordered lists (UL).  Converting that into table markup, what I get is a set of nested tables.

    As for your problem, Have you referred to the following article?

    Best Regards,

    Sw-ing

    Wednesday, October 22, 2014 5:07 AM
  • User846546683 posted

    Yes, I looked at the link before. Notice that the title says "WITHOUT using tables."

    I want my output to BE a table and not a nested unordered list.

    As it turns out someone helped me last night.  Here what worked for me.

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" 
    exclude-result-prefixes="map">
    <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
    
    <xsl:template match="/map:siteMap">
        <table>
            <xsl:apply-templates select="map:siteMapNode"/>
        </table>
    </xsl:template>
    
    <xsl:template match="map:siteMapNode">
        <tr>
            <td>
                <a href="{@url}"><xsl:value-of select="@title"/></a>
            </td>
            <td>
                <xsl:value-of select="@description"/>
            </td>
        </tr>
        <xsl:apply-templates select="map:siteMapNode"/>
    </xsl:template>
    
    </xsl:stylesheet>



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 22, 2014 9:36 AM