我有这个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 :(得分: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格式化它而不是创建单独的循环可能更有效