我使用Diazo/XSLT来主题Plone网站。在主页上,Plone的给了我以下结构:XSLT/Diazo:为每对元素创建元素
<dl>
<dt>
<a href="...">The news item title</a>
</dt>
<dd>
The content of the news item
</dd>
(and so on for the following ones)
</dl>
,我要变成这样的事情:
<div id="news_items">
<div>
<h2><a href="...">The news item title</a></h2>
The content of the news item.
<a class="readmore" href="<the HREF taken from the dt/a tag)">Read more</a>
</div>
(and so on for the following items)
</div>
我不是很熟悉XSLT和重氮(多用来重写一些现有的主题),但我尝试了一些解决方案。
第一个是两次做这个。每个“DD”标签首先来看,造成结构和更新通过解析所有的“DT”标签后:
<copy css:theme="#news_items">
<xsl:for-each css:select="#content-core dl dd">
<xsl:element name="div">
<xsl:element name="h2">
</xsl:element>
<xsl:copy-of select="./*" />
<xsl:element name="a">
<xsl:attribute name="class">readmore</xsl:attribute>
Read more
</xsl:element>
</xsl:element>
</xsl:for-each>
</copy>
它正确地创建结构,但我不知道怎么写的第二部分。这个想法是这样的事情:
<xsl:for-each css:select="#content-core dl dt">
<!-- Copy the link in the 'dd' tag into the h2 tag, based on the position -->
<copy css:theme="#news_item div:nth-child(position()) h2" css:select="a" />
<!-- Copy the a tag's href in the 'Read more' tag -->
<copy css:theme="#news_item div:nth-child(position()) a.readmore">
<xsl:attribute name="class">
<xsl:value-of select="@class" />
</xsl:attribute>
</copy>
</xsl:for-each>
我知道它没有那么多道理,但我希望你得到它的想法:
我看着每一个“DD”标签
我发现,根据循环中的位置,在上一步创建的'h2'标签,我复制“dd”标签内的链接。
我发现(基于位置再次)“a.readmore”标记并复制href。
我一直在想的第二种解决方案有点肮脏(也不管用)。这个想法是在一个步骤中创建的内容:
<xsl:for-each css:select="#content-core dl > *">
<xsl:if test="name = dt">
<!-- That the dt tag, we start the 'div' tag and add the h2 tag -->
</xsl:if>
<xsl:if test="name = dt">
<!-- That the dt tag, we copy the content and close the 'div' tag -->
</xsl:if>
</xsl:foreach>
但我真的不喜欢的解决方案(我不明白如何创建“阅读更多”链接)。
您认为第一个解决方案可以完成吗? (尤其是第二步填充“h2”标签并在“阅读更多”链接上添加“href”属性)。 有没有更好的解决方案?
我宁愿只用重氮,但如果它是不可行的,我可以直接覆盖在Plone的观点(这将是简单的,我认为,至少我知道该怎么做)
谢谢您帮帮我。