Xslt 如何使用xsl输出此html(我想退出一个元素)
我有以下xsl规范:Xslt 如何使用xsl输出此html(我想退出一个元素),xslt,Xslt,我有以下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/DataV
<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>
- 宏达电
- 诺基亚
HTC感知345-HTC电动汽车
诺基亚
但现在这就是我得到的
<div id="vtab">
<ul>
<li>HTC</li>
<div>HTC Sensation 345HTC Evo</div>
<li>Nokia</li>
<div>Nokia</div>
</ul>
</div>
- 宏达电
HTC感应345 HTC Evo
- 诺基亚
诺基亚
如何退出UL元素并启动DIV元素。
谢谢AOT
它不是最优的,但是考虑两个循环类似如下:
<?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格式化可能比创建单独的循环更有效您如何拥有这样的代码?不介意,但它看起来不那么可读!这对于初学者来说是可以接受的,但你是一个200+分数的用户!?Aravind我的坏蛋。这是我从Sharepoint Designer得到的,正如你所知,它的格式不好:(请注意,这不是完整的XSLT,因为原始示例中没有显示键。谢谢Chris。这帮助我得到了我想要的。之前没有添加:到我的孩子