我想包括在所有页面的设计,为此我设置了一个母版页布局,它的工程perfect.Then我想添加一些部分到我的网站的每个页面,我也是通过创建一个实用程序页面,但问题是重复所有的内容。以下是我的代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/data">
<h1><xsl:value-of select="$page-title"/></h1>
<ul><xsl:apply-templates select="/categories/entry"/></ul>
</xsl:template>
<xsl:template match="categories/entry">
<div class="left_wrap">
<div class="large_video"><img src="{$workspace}/images/video.jpg" style="border:#393939 solid 1px;" /></div>
<div class="title1">Categories<img src="{$workspace}/images/arrow.jpg" /></div>
<div style="float:left; width:680px;">
<div class="category_block">
<div class="category_title"><xsl:value-of select="title"/></div>
<div class="category_image"><img src="{$workspace}/images/politics.jpg" /></div>
<div class="category_info"><xsl:value-of select="description"/></div>
<div class="date"><img src="{$workspace}/images/time.png" style="float:left;"/><p style="float:left; width:120px; margin-left:6px;">2 days ago</p></div>
</div><!--category_block END-->
</div>
</div>
</xsl:template>
</xsl:stylesheet> 我只想重复"class='category_block'“div,但我需要在此页面中使用所有其他的div。交响乐怎么可能做到这一点?另外,我想在我的主页中限制类别描述字符数为100个字符,我如何才能限制它。
发布于 2011-07-14 20:38:58
首先,您的<div class="left-wrap">是否意味着每个类别条目都要重复,还是应该包含所有类别?我将假设是后者,因为考虑到我在这里看到的情况,这似乎是最有意义的。
如果是这样的话,您的data模板应该如下所示:
<xsl:template match="data">
<h1><xsl:value-of select="$page-title"/></h1>
<xsl:apply-templates select="categories"/>
</xsl:template>这将与categories节点匹配,并允许您为所有类别条目设置容器:
<xsl:template match="categories">
<div class="left_wrap">
<div class="large_video">
<img src="{$workspace}/images/video.jpg" style="border:#393939 solid 1px;" />
</div>
<div class="title1">Categories<img src="{$workspace}/images/arrow.jpg" /></div>
<div style="float:left; width:680px;">
<ul>
<!-- This will be your repeating block -->
<xsl:apply-templates select="entry"/>
<ul>
</div>
</div>
</xsl:template>现在,当您有多个entry时,下面的entry模板中的任何内容都将对每个will重复:
<xsl:template match="categories/entry">
<li>
<div class="category_block">
<div class="category_title">
<xsl:value-of select="title"/>
</div>
<div class="category_image">
<img src="{$workspace}/images/politics.jpg" />
</div>
<div class="category_info">
<xsl:value-of select="description"/>
</div>
<div class="date">
<img src="{$workspace}/images/time.png" style="float:left;"/>
<p style="float:left; width:120px; margin-left:6px;">2 days ago</p>
</div>
</div><!--category_block END-->
</li>
</xsl:template>显然,我不得不在这里做一些假设,所以如果这不是你想要的,请告诉我。此外,请记住,使用XSLT总有多种方法可以完成某些工作。
最后,您应该考虑清理一下您的标记。大量无关的、非语义的div等等。例如,您的<div class="title1">可能应该是一个标题。<div class="category_title">也是如此。
要回答关于截断描述的最后一个问题,请尝试来自Symphony站点的this utility。
https://stackoverflow.com/questions/6692452
复制相似问题