2012-03-16 32 views
-3

我有这样的XSL波纹管:我该如何输出这个网站使用XSL(我想退出的元素)

<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls"> 
    <div id="vtab"> 
    <ul> 
     <xsl:call-template name="dvt_1.body"/> 
    </ul> 
    </div> 
</xsl:template> 

<xsl:template name="dvt_1.body"> 
    <xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', @Title))]"> 
    <li> 
     <xsl:value-of select="@Title"/> 
    </li> 
    <xsl:variable name="thisClassification" select="@Title" /> 
    <div> 
     <xsl:for-each select="../Row[@Title = $thisClassification]"> 
     <xsl:value-of select="@Model"/> 
     </xsl:for-each> 
    </div> 
    </xsl:for-each> 
</xsl:template> 

我想有这样的输出:

   <div id="vtab"> 
       <ul> 
        <li>HTC</li> 
        <li>Nokia</li> 

       </ul> 
        <div>HTC Sensation 345-HTC Ev</div> 
        <div>Nokia</div> 
       </div> 

但现在这是我得到什么

<div id="vtab"> 
<ul> 
<li>HTC</li> 
<div>HTC Sensation 345HTC Evo</div> 
<li>Nokia</li> 
<div>Nokia</div> 
</ul> 
</div> 

我如何退出UL元素并启动DIV元素。 非常感谢

+0

你怎么能有这样的代码?不介意,但它看起来不太可读!对于初学者来说这是可以接受的,但是你是一个200分以上的用户!? – 2012-03-16 05:37:45

+0

编辑为格式良好。 – 2012-03-16 05:43:39

+0

Aravind我的坏家伙,我从Sharepoint设计师那里得到了什么,而且你知道它的格式不好:( – naijacoder 2012-03-23 21:38:23

回答

0

这是不是最佳的,但考虑做两个循环类似如下:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template match="/"> 
     <div id="vtab"> 
      <xsl:call-template name="LOOP_1"/> 
      <xsl:call-template name="LOOP_2"/> 
     </div> 
    </xsl:template> 
    <xsl:template name="LOOP_1"> 
     <ul> 
      <xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', @Title))]"> 
       <li> 
        <xsl:value-of select="@Title"/> 
       </li> 
       <xsl:variable name="thisClassification" select="@Title"/> 
       <div> 
        <xsl:for-each select="../Row[@Title = $thisClassification]"> 
         <xsl:value-of select="@Model"/> 
        </xsl:for-each> 
       </div> 
      </xsl:for-each> 
     </ul> 
    </xsl:template> 
    <xsl:template name="LOOP_2"> 
     <div> 
      <xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', @Title))]"> 
       <xsl:variable name="thisClassification" select="@Title"/> 
       <div> 
        <xsl:for-each select="../Row[@Title = $thisClassification]"> 
         <xsl:value-of select="@Model"/> 
        </xsl:for-each> 
       </div> 
      </xsl:for-each> 
     </div> 
    </xsl:template> 
</xsl:stylesheet> 

我不知道你的要求,但它可能是更有效的审查所需的输出,以及输出嵌套列表并使用CSS格式化,而不是创建单独的循环

+0

请注意,这并不是完整的XSLT,因为原始示例中未显示密钥 – 2012-03-16 05:40:30

+0

感谢Chris.That帮助我得到了我想要的。 没有添加: 给我的孩子 – naijacoder 2012-03-16 06:37:33

相关问题