L'esempio seguente visualizza la struttura dei menu di SharePoint, contenuto nel file XML, in un formato ad albero espandibile (XSL con JavaScript).

XML: SPMenu.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="SPMenu.xsl" ?>
<home version="Portal 2003">
  <mnu value="Site Setting" page="/_layouts/1033/default.aspx">
	Use this page to administer general settings, users and content.
    <section value="General Settings">
	  Manage users, permissions and default settings for this portal site.
      <mnu value="Manage users" page="/_layouts/1033/User.aspx">
	    Gestione utente
	  </mnu>
      <mnu value="Manage security and additional settings" page="/_layouts/1033/PortalSettings.aspx">
	    Use this page to manage additional settings for this portal site.
        <section value="Users and Permissions">
          <mnu value="Manage users" page="/_layouts/1033/User.aspx" />
          <mnu value="Manage site groups" page="/_layouts/1033/role.aspx" />
          <mnu value="Show user information" page="/_layouts/1033/UserInfo.aspx">
		    Use this page to view a list of all users who have participated in or have been added to this Web site. To view a user's information, click the user's display name.
		  </mnu>
          <mnu value="Change anonymous access settings" page="/_layouts/1033/spanon.aspx">
		    Use this page to allow or deny anonymous users access to your Web site.
		  </mnu>
        </section>
        <section value="Templates and Web Parts">
          <mnu value="Manage Web Part gallery" page="/_catalogs/wp/Forms/AllItems.aspx" >
		    Use this Web Part Gallery to store and retrieve Web Parts. The Web Parts in this gallery are available to this site and all sites under it. To preview a Web Part, click its title.
		  </mnu>
          <mnu value="Manage site template gallery" page="/_catalogs/wt/Forms/AllItems.aspx" >
		    Make a template available for use in Web site creation by adding it to this gallery. The templates in this gallery are available to this site and all sites under it. Default site templates are not shown.
		  </mnu>
          <mnu value="Manage list template gallery" page="/_catalogs/lt/Forms/AllItems.aspx" >
		    Make a template available for use in list creation by adding it to this gallery. The templates in this gallery are available to this site and all sites under it. Default list templates are not shown.
		  </mnu>
        </section>
        <section value="Discussion Settings">
          <mnu value="Manage Web Discussions" page="/_layouts/1033/MngDisc.aspx" >
		    The following list shows the URLs of documents that have Web Discussions maintained by this site. To view all URLs with discussions on your site, select All Web Discussions, and then click Update. To view the list of URLs in a particular folder, select Web Discussions in folder, type the folder name, and then click Update.
		  </mnu>
        </section>
        <section value="Storage Space">
          <mnu value="Manage storage space allocation" page="/_layouts/1033/StorMan.aspx" >
		    Storage Space Allocation.
		  </mnu>
        </section>
        <section value="Regional Settings">
          <mnu value="Modify regional settings" page="/_layouts/1033/RegionalSetng.aspx" >
		    Use this page to set regional settings such as the locale and time zone for this site.
		  </mnu>
        </section>
      </mnu>
      <mnu value="Manage alerts settings" page="/_layouts/1033/AlertsAdmin.aspx" >
	    Use this page to manage settings for alerts and alert results for all users.
	  </mnu>
      <mnu value="Change portal site properties and SharePoint site creation settings" page="/_layouts/1033/PortalProperties.aspx" >
	    Use this page to view and change properties for the portal site.
	  </mnu>
      <mnu value="Go to SharePoint Portal Server central administration">
        da controllare !?!?!?
      </mnu>
      <mnu value="Manage users" />
    </section>
    <section value="Portal Site Content" >
	  Manage content for this portal site.
      <mnu value="Manage portal site structure" page="/_layouts/1033/CatMan.aspx?Everything=1" >
	    This is a view of the structure of the portal. From this view, you can drag areas and listings to new locations. You can also limit the view to only the current area by clicking Filter on the area's menu. To go back to the whole list, click Reset.
	  </mnu>
      <mnu value="Manage top-level lists and document libraries" page="/_layouts/1033/spsViewLsts.aspx" >
	    This page shows all the libraries, lists, discussion boards, and surveys in this Web site. Click the name of a library or list to view its contents. To create a new library or list, click Create.
	  </mnu>
      <mnu value="Use Topic Assistant" page="/_layouts/1033/AutoCat.aspx" />
      <mnu value="Manage targeted links on My Site" page="/_layouts/1033/lstman2.aspx" >
	    All Listings: Targeted links on My Site: This is a view of all listings in this area.
      </mnu>
      <mnu value="Import Microsoft SharePoint Portal Server 2001 data" page="/_layouts/1033/ImportData.aspx" >
	    Use this page to import the Microsoft SharePoint Portal Server 2001 data.
      </mnu>
    </section>
    <section value="Search Settings and Indexed Content" >
      Manage content included in the content indexes for this portal site and configure content available for searching.
      <mnu value="Configure search and indexing" page="/_layouts/1033/SearchSettings.aspx" >
	    Use this page to configure what content will be available when searching from the portal.
        <section value="General Content Settings and Indexing Status" >
	      Use this section to monitor and manage general crawl settings.
          <mnu value="Refresh" />
          <mnu value="Manage search schedules" />
          <mnu value="View errors and warnings on: portal content | non portal content " />
          <mnu value="Manage search scopes" />
          <mnu value="Include file types" />
          <mnu value="Exclude and include other content " />
          <mnu value="Add content source" />
          <mnu value="Enable advanced search administration mode" />
        </section>
        <section value="Site Directory" >
		  This section enables you to specify crawling options for sites in the Site Directory.
          <mnu value="Refresh" />
          <mnu value="Manage crawls of Site Directory" >
		    View sites pending approval for indexing.
          </mnu>
          <mnu value="Add Site Directory content source" >
		    Add Content Source
          </mnu>
          <mnu value="Add Link to Site" >
		    Use this page to add a link to a site to the Site Directory. This makes the site available for users searching or browsing for sites.
          </mnu>
        </section>
        <section value="Other Content Sources" >
		  This section enables you to create and manage content sources for items that cannot be included in the Site Directory and for items that should not appear in the Site Directory.
          <mnu value="Refresh" />
          <mnu value="Add content source" >
            Use this page to add a content source.
          </mnu>
          <mnu value="Manage content sources" >
		    Use this page to add, edit, or delete content sources, and to manage updates.
          </mnu>
        </section>
      </mnu>
      <mnu value="Manage search scopes" page="/_layouts/1033/listsearchscopes.aspx" >
	    Use this page to view and manage the search scopes The order in which the search scopes appear in this list is the order in which they will appear in the search scope list next to the Search box.
      </mnu>
      <mnu value="Use search scope from another portal site" page="/_layouts/1033/AssociatePortal.aspx" >
	    Associate Portal Site: In a shared services environment, you can associate this portal with the search scope of another portal. Search results on the associated portal will then include the contents of this portal.
      </mnu>
      <mnu value="Manage properties from crawled documents" page="/_layouts/1033/Properties.aspx" >
	    Manage Properties of Crawled Content: Use this page to view and manage properties associated with crawled documents. To hide or show properties not displayed in search, select or clear the Hide excluded properties check box.
      </mnu>
      <mnu value="Manage crawls of Site Directory" page="/_layouts/1033/SRMan.aspx?ConsoleView=IndexPending" >
	    View sites pending approval for indexing: This page lists the sites that users requested to appear in search results. They are pending your approval. You may choose to index the site in a specific scope or exclude the sites from all scopes.
      </mnu>
      <mnu value="Manage keywords" page="/_layouts/1033/KeywordBBMan.aspx?ConsoleView=KeywordViewItem&Everything=" >
	    Keywords: This is a list of keywords in the portal site.
      </mnu>
    </section>
    <section value="User Profile, Audiences, and Personal Sites" >
	  Manage user profiles, define audiences for content customization, and manage personal sites
      <mnu value="Manage profile database" page="/_layouts/1033/ProfMain.aspx" >
	    Use this page to manage user profiles.
        <section value="Profile and Import Settings" >
		  Use these links to manage user profiles for this site and import new profiles from the Active Directory directory service.
          <mnu value="Refresh" />
          <mnu value="Add user profile" >
		    Use this page to add a user profile by typing values for the following properties.
          </mnu>
          <mnu value="View user profiles" >
		    Use this page to manage the user profiles in the portal database. From this page you can delete and deactivate alerts for individual users.
          </mnu>
          <mnu value="Configure profile import" >
		    Use this page to configure settings for importing user profiles from Active Directory directory service.
          </mnu>
          <mnu value="Start full import" />
          <mnu value="Start incremental import" />
          <mnu value="Stop import" />
          <mnu value="Manage connections" >
		    Use this page to manage the list of connections to Active Directory directory service domain controllers. The portal site will import user information from these domain controllers.
          </mnu>
          <mnu value="View import log" />
        </section>
        <section value="User Profile Properties" page="/_layouts/1033/Audience_Main.aspx" >
		  Use these links to manage the properties of user profiles.
          <mnu value="Add profile property" >
		    Use this page to add a property for user profiles.
          </mnu>
          <mnu value="View profile properties" >
		    Use this page to add, edit, or delete user profile properties. You can organize the user profile properties into sections. You can also map a property to a property in Active Directory directory services.
          </mnu>
        </section>
      </mnu>
      <mnu value="Manage audiences" page="/_layouts/1033/PersonalSites.aspx" >
		Use this page to manage and compile audiences.
        <section value="Audience Settings">
	      Use this page to manage and compile audiences.
          <mnu value="Refresh" />
          <mnu value="Create audience" >
		    Use this page to create an audience. To add members, add rules that identify matching users.
          </mnu>
          <mnu value="View audiences" >
		    Use this page to view audience properties, add and edit audiences, and view audience membership.
          </mnu>
          <mnu value="Specify compilation schedule" >
	        Use this page to specify a schedule for audience compilation.
          </mnu>
          <mnu value="Start compilation" />
        </section>
      </mnu>
      <mnu value="Manage personal sites" >
	    Use this page to manage default personal site settings for this portal site.
      </mnu>
    </section>
  </mnu>
  <mnu value="Action">
    <mnu value="Add Listing" page="/_layouts/1033/spnewlisting.aspx" >
	  Use this page to add a listing to an area. Listings in this area may require approval before they are displayed.
    </mnu>
    <mnu value="Create Area" page="/_layouts/1033/spnewcategory.aspx" >
	  Use this page to create an area.
    </mnu>
    <mnu value="Upload Document" page="/Document%20Library/Forms/Upload.aspx" />
    <mnu value="Change Settings" page="/_layouts/1033/SPEditCategory.aspx" >
	  Use this page to change the general settings associated with this area. Click the tabs to change other settings related to this area.
    </mnu>
    <mnu value="Manage Users" page="/_layouts/1033/User.aspx" >
	  Use this page to add new users, remove users from all site groups, or assign users to site groups. The following users have been added to this Web site. To edit which site groups a user belongs to, click the user's name in the list.
    </mnu>
    <mnu value="Manage Content" page="/_layouts/1033/spsviewlsts.aspx" >
	  Documents and Lists: This page shows all the libraries, lists, discussion boards, and surveys in this Web site. Click the name of a library or list to view its contents. To create a new library or list, click Create.
    </mnu>
    <mnu value="Manage Portal Site" page="/_layouts/1033/catman.aspx" >
	  Portal Site Map: This is a view of the structure of the portal. From this view, you can drag areas and listings to new locations. You can also limit the view to only the current area by clicking Filter on the area's menu. To go back to the whole list, click Reset.
    </mnu>
    <mnu value="Edit Page" page="/default.aspx?Mode=Edit&PageView=Shared" />
  </mnu>
</home>

XML: SPMenu.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" encoding="iso-8859-1" version="4.01" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
 <xsl:template match="/home">
  <html>
    <head>
      <title><xsl:value-of select="@version" /></title>
      
      <style type="text/css">
        body { font-family: verdana; font-size: 8pt;}
        img { border: 0; }
        #tree { width:100%; padding: 5px; }
        #tree ul { list-style-type: none; padding: 0; margin:0;  margin-left: 2em; }
        #tree ul img.pm {}
        #tree ul li p {font-size: 7pt; color: #a0a0a0;;
         padding: .1em; padding-left: 2em; margin: 0;}
        /*
        #tree ul li img.ty { background: url(plus.gif) 0 0 no-repeat;border-width: 2px; border-style: outset;} 
        #tree ul li li img.ty { background: url(minus.gif) 0 0 no-repeat; border-width: 2px; border-style: outset;}
        */
        #tree ul li span { padding-left: .5em; }
      </style>
      
      <script language="javascript">
        function tm(id) {
          var obj = document.getElementById("m" + id);
          obj.style.display = (obj.style.display == "none") ? "block" : "none";
          var objImg = document.getElementById("i" + id);
          if (objImg != null) {
            objImg.src = (obj.style.display == "none") ? "minus.gif" : "plus.gif";
          }
        }
      </script>
    </head>

    <body>
      <div id="tree">
        <img src="plus.gif" onclick="tm('{generate-id(.)}')" /> Home
        <xsl:call-template name="parseNode"/>
      </div>
    </body>

    </html>
    
  </xsl:template>
  
  <xsl:template name="parseNode">
  <ul id="m{generate-id(.)}">
    <xsl:for-each select="child::*">
    <xsl:variable name="gid" select="generate-id(.)" /> 
    <li>
      <xsl:choose>
        <xsl:when test="count(child::*) > 0">
          <img src="minus.gif" id="i{$gid}" class="pm" onclick="tm('{$gid}')" />
          <img id="t{$gid}" class="ty" width="16" height="16">
            <xsl:attribute name="src">
              <xsl:choose>
                <xsl:when test="name() = 'mnu'">caOpen.gif</xsl:when>
                <xsl:otherwise>cgClose.gif</xsl:otherwise>
              </xsl:choose>
            </xsl:attribute>
          </img>
          <xsl:call-template name="mnuValue"/>
          <xsl:call-template name="parseNode"/>
        </xsl:when>
        <xsl:otherwise>
          <img src="nochild.gif" id="i{$gid}" class="pm" />
          <xsl:call-template name="mnuValue"/>
        </xsl:otherwise>
      </xsl:choose>
    </li>
      </xsl:for-each>
     </ul>
  </xsl:template>

  <xsl:template name="mnuValue">
  <span><b><xsl:value-of select="@value" /></b></span>
  <xsl:if test="@page">
    <xsl:text> </xsl:text>
    <a href="{@page}" target="spp"><img src="url.gif" /></a>
  </xsl:if>
  <p><xsl:value-of select="text()" /></p>
 </xsl:template>
 
</xsl:stylesheet>
I file devo essere nella stessa cartella.

Nel file XSL si può vedere il funzionamento:
  • del tag xsl:template e la sua chiamata xsl:call-template (concettualmente delle subroutine)
  • la definizione variabili xsl:variable e al loro richiamo tramite i $nome
  • l'utilizzo delle funzioni o dei parametri tramite l'uso delle parentesi graffe { ... } (es. {generate-id(.)} ) all'interno degli attributi (senza usare xsl:attribute)
  • del tag xsl:for-each per ciclare su un insieme di nodi
  • del tag xsl:if e xsl:choose per esegure dei test
  • di alcune funzioni come count(), name() e generate-id(.)
  • della @ per accedere agli attributi (es. @page)

Vedi esempio SpMenu.xml
Esempio di output
Esempio di output
Tags:
HTML74 JavaScript184 SharePoint497 XML / XSL / XSLT29
Potrebbe interessarti anche: