简体   繁体   English

可以将web.sitemap查看为表格吗?

[英]Is it possible to view web.sitemap as a table?

Is it possible to use XSLT to display a nested web.sitemap into a single non-nested table? 是否可以使用XSLT将嵌套的web.sitemap显示到单个非嵌套表中?

Looking around on the web, I found some XSLT code that transforms a web.sitemap file into a nested set of unordered lists (UL). 在网上浏览时,我发现了一些XSLT代码,这些代码将一个web.sitemap文件转换为一组嵌套的无序列表(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? 有人知道如何将其呈现为单个表-而不是嵌套表吗?

For those who want to know why I am asking this and what I'm trying to do, I'm trying to fill a client request to read the sitemap but present it as a table rather than as an asp.navigation control (which is my default action). 对于那些想知道我为什么要问这个问题以及我想做什么的人,我试图满足客户要求以读取站点地图,但将其显示为表格而不是asp.navigation控件(我的默认操作)。 If there is a better way to do this, I'm open to ideas. 如果有更好的方法可以做到这一点,我欢迎您提出意见。 This was my best theory based on what I have been able to find by web search. 根据我在网络搜索中找到的内容,这是我最好的理论。

Thank you for any ideas. 谢谢您的任何想法。

<?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>

I'm mostly guessing here, but I think you want something like: 我主要是在这里猜测,但我认为您想要的是:

XSLT 1.0 XSLT 1.0

<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>

Applied to the following example input : 应用于以下示例输入

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
  <siteMapNode title="Home" description="Home" url="~/default.aspx">
    <siteMapNode title="Products" description="Our products" url="~/Products.aspx">
      <siteMapNode title="Hardware" description="Hardware choices" url="~/Hardware.aspx"/>
      <siteMapNode title="Software" description="Software choices" url="~/Software.aspx"/>
    </siteMapNode>
    <siteMapNode title="Services" description="Services we offer" url="~/Services.aspx">
      <siteMapNode title="Training" description="Training classes" url="~/Training.aspx"/>
      <siteMapNode title="Consulting" description="Consulting services" url="~/Consulting.aspx"/>
      <siteMapNode title="Support" description="Supports plans" url="~/Support.aspx"/>
    </siteMapNode>
  </siteMapNode>
</siteMap>

produces the result : 产生结果

<table>
   <tr>
      <td>
         <a href="~/default.aspx">Home</a>
      </td>
      <td>Home</td>
   </tr>
   <tr>
      <td>
         <a href="~/Products.aspx">Products</a>
      </td>
      <td>Our products</td>
   </tr>
   <tr>
      <td>
         <a href="~/Hardware.aspx">Hardware</a>
      </td>
      <td>Hardware choices</td>
   </tr>
   <tr>
      <td>
         <a href="~/Software.aspx">Software</a>
      </td>
      <td>Software choices</td>
   </tr>
   <tr>
      <td>
         <a href="~/Services.aspx">Services</a>
      </td>
      <td>Services we offer</td>
   </tr>
   <tr>
      <td>
         <a href="~/Training.aspx">Training</a>
      </td>
      <td>Training classes</td>
   </tr>
   <tr>
      <td>
         <a href="~/Consulting.aspx">Consulting</a>
      </td>
      <td>Consulting services</td>
   </tr>
   <tr>
      <td>
         <a href="~/Support.aspx">Support</a>
      </td>
      <td>Supports plans</td>
   </tr>
</table>

rendered as: 呈现为:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM