对 XSLT 变量日期进行排序
抱歉,如果我在上一个“问题”中的解释有点粗糙,我会再试一次。我对 xsl 真的很陌生。
通过一系列子字符串,我通过将日期字段存储在名为 $releasedate
的变量中来提取日期字段,我使用
它将在“foreach”循环中显示 dd/mm/yyyy,例如 29/03/2010,如下所示。
我的 xml 结构类似于下面,
<item>
<title>Title Goes Here</title>
<description>test goes here.....<b>Release Date:22/20/2010</b> more text</description>
</item>
<item>
<title>Title Goes Here</title>
<description>More test goes here.....<b>Release Date:22/20/2010</b> more text</description>
</item>
我希望能够按 $releasedate 中存储的值进行排序。 我想也许它看起来像下面这样,
<xsl:sort select="$releasedate" order="descending" />
我希望这更有意义,我再次为我缺乏这方面的知识而道歉。
下面是我的xsl结构
<xsl:for-each select="item">
<xsl:sort select="pubDate"/>
<xsl:if test="position() < 5 ">
<!-- grabs items 1 to 5 -->
<xsl:variable name = "releasedatestart" >
<xsl:value-of select="substring-after(description,'Release Date:</b>')"/>
</xsl:variable>
<xsl:variable name = "releasedate" >
<xsl:value-of select="substring-before($releasedatestart,'</div>')"/>
</xsl:variable>
<xsl:variable name = "displaynamestart" >
<xsl:value-of select="substring-after(description,'Display Name:</b>')"/>
</xsl:variable>
<xsl:variable name = "displayname" >
<xsl:value-of select="substring-before($displaynamestart,'</div>')"/>
</xsl:variable>
<div style="margin:0px;background-color:#f2eff3;border:1px solid #ded6df;">
<xsl:variable name = "start" >
<xsl:value-of select="substring-after(description,'Description:</b>')"/>
</xsl:variable>
<xsl:variable name = "title" >
<xsl:value-of select="substring($start,0,100)"/>
</xsl:variable>
<xsl:variable name = "pagelink" >
<xsl:value-of select="substring(link,1,61)"/>
</xsl:variable>
<xsl:variable name = "pageurl" >
<xsl:value-of select="$pagelink"/>
<xsl:value-of select="title"/>.aspx
</xsl:variable>
<div style="min-height:50px;">
<div class="column" id="feeddate">
<xsl:value-of select="$releasedate" />
</div>
<div class="column" id="displayname">
<xsl:value-of select="$displayname" />
</div>
<div class="column" id="feedtitle">
<xsl:value-of select="$title" disable-output-escaping="yes"/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$pageurl" />
</xsl:attribute>
..Read More
</a>
</div>
</div>
</div>
</xsl:if>
</xsl:for-each>
Sorry if my explanation in the last 'question' was a little rough, I'll give it another shot.I'm really new to xsl.
Through a series of substrings I have extracted the date field by storing it in a variable called $releasedate
, I output this by using <xsl:value-of select="$releasedate" />
which would display dd/mm/yyyy e.g. 29/03/2010 in a 'for each' loop as shown below.
My xml is structured similar to below,
<item>
<title>Title Goes Here</title>
<description>test goes here.....<b>Release Date:22/20/2010</b> more text</description>
</item>
<item>
<title>Title Goes Here</title>
<description>More test goes here.....<b>Release Date:22/20/2010</b> more text</description>
</item>
I would like to be able to sort by the value of what is stored in $releasedate.
I think maybe it would look like this below
<xsl:sort select="$releasedate" order="descending" />
I hope this makes a little more sense, my appologies again for my lack of knowledge in this.
Below is my xsl structure
<xsl:for-each select="item">
<xsl:sort select="pubDate"/>
<xsl:if test="position() < 5 ">
<!-- grabs items 1 to 5 -->
<xsl:variable name = "releasedatestart" >
<xsl:value-of select="substring-after(description,'Release Date:</b>')"/>
</xsl:variable>
<xsl:variable name = "releasedate" >
<xsl:value-of select="substring-before($releasedatestart,'</div>')"/>
</xsl:variable>
<xsl:variable name = "displaynamestart" >
<xsl:value-of select="substring-after(description,'Display Name:</b>')"/>
</xsl:variable>
<xsl:variable name = "displayname" >
<xsl:value-of select="substring-before($displaynamestart,'</div>')"/>
</xsl:variable>
<div style="margin:0px;background-color:#f2eff3;border:1px solid #ded6df;">
<xsl:variable name = "start" >
<xsl:value-of select="substring-after(description,'Description:</b>')"/>
</xsl:variable>
<xsl:variable name = "title" >
<xsl:value-of select="substring($start,0,100)"/>
</xsl:variable>
<xsl:variable name = "pagelink" >
<xsl:value-of select="substring(link,1,61)"/>
</xsl:variable>
<xsl:variable name = "pageurl" >
<xsl:value-of select="$pagelink"/>
<xsl:value-of select="title"/>.aspx
</xsl:variable>
<div style="min-height:50px;">
<div class="column" id="feeddate">
<xsl:value-of select="$releasedate" />
</div>
<div class="column" id="displayname">
<xsl:value-of select="$displayname" />
</div>
<div class="column" id="feedtitle">
<xsl:value-of select="$title" disable-output-escaping="yes"/>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$pageurl" />
</xsl:attribute>
..Read More
</a>
</div>
</div>
</div>
</xsl:if>
</xsl:for-each>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此转换:
应用于此文档时:
产生所需的排序结果:
说明:
使用
substring-after()
和substring()
。
的多个
子级。身份转换。
This transformation:
when applied on this document:
produces the wanted, sorted result:
Explanation:
Use of
substring-after()
andsubstring()
.Multiple
<xsl:sort>
children of<xsl:apply-templates>
.Identity transform.