我一直在努力与发现(使用)两个日期之间的差异。
XSL 2.0是不是一种选择,但我发现EXSLT日期:差异http://exslt.org/date/functions/difference/可能解决我的问题在XSL 1.0比较日期-但是,我还没有发现任何的好例子关于如何使用它。
我有一个XML文件看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="gall.xsl"?>
<report>
<title>Individual Item Display</title>
<dateCreated>2016-05-23T14:26:33</dateCreated>
<dateFormat>yyyy/mm/dd</dateFormat>
<catalog>
<catalogKey>100904</catalogKey>
<yearOfPublication>1982</yearOfPublication>
<marc>
<marcEntry tag="100" label="Personal Author" ind="1 ">Linderholm, Helmer, 1916-1982</marcEntry>
<marcEntry tag="245" label="Title" ind="00">Tre ogärningskvinnor / Helmer Linderholm</marcEntry>
</marc>
<call>
<callNumber>HC</callNumber>
<item>
<totalCharges>0</totalCharges>
<intervalCheckouts>0</intervalCheckouts>
<intervalRenewals>0</intervalRenewals>
<dateLastUsed>2014-06-17</dateLastUsed>
<itemID>30580000599535</itemID>
<library>VALLA</library>
<location>SKÖNLITT</location>
<type>HEMLAN</type>
<dateCreated>1996-06-20</dateCreated>
</item>
</call>
</catalog>
<catalog>
<catalogKey>100955</catalogKey>
<yearOfPublication>1983</yearOfPublication>
<marc>
<marcEntry tag="100" label="Personal Author" ind="1 ">Linderholm, Helmer, 1916-82</marcEntry>
<marcEntry tag="245" label="Title" ind="10">Fredens hemliga stig / Helmer Linderholm</marcEntry>
</marc>
<call>
<callNumber>H,U</callNumber>
<item>
<totalCharges>2</totalCharges>
<intervalCheckouts>0</intervalCheckouts>
<intervalRenewals>0</intervalRenewals>
<dateLastUsed>2006-12-18</dateLastUsed>
<itemID>30580001728125</itemID>
<library>VALLA</library>
<location>ULITT</location>
<type>HEMLAN</type>
<dateCreated>1996-06-20</dateCreated>
</item>
</call>
</catalog>
<catalog>
<catalogKey>100901</catalogKey>
<yearOfPublication>1982</yearOfPublication>
<marc>
<marcEntry tag="100" label="Personal Author" ind="1 ">Linderholm, Helmer, 1916-1982</marcEntry>
<marcEntry tag="245" label="Title" ind="00">I de rödas krig / Helmer Linderholm</marcEntry>
</marc>
<call>
<callNumber>H,U</callNumber>
<item>
<totalCharges>1</totalCharges>
<totalCheckouts>0</totalCheckouts>
<totalRenewals>0</totalRenewals>
<intervalCheckouts>0</intervalCheckouts>
<intervalRenewals>0</intervalRenewals>
<intervalStartDate>2016-01-01</intervalStartDate>
<recirculate>YES</recirculate>
<dateLastUsed>2006-12-18</dateLastUsed>
<isReserveItem>false</isReserveItem>
<copyNumber>1</copyNumber>
<itemID>30580001728158</itemID>
<library>VALLA</library>
<location>ULITT</location>
<type>HEMLAN</type>
<dateCreated>1996-06-20</dateCreated>
</item>
</call>
</catalog>
</report>
首先,我要过滤 - 因此它仅包含项目,其中dateLastUsed是老年人,5年。 我认为一个如果子句将做到这一点,但任何建议,欢迎!
其次我想,说一个领域 - 优选以年 - 月 - 日 - 自dateLastUsed多久时间已经过去了。
这是我初步的样式表 - 我对如何proceeed毫无头绪。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
extension-element-prefixes="date">
<xsl:import href="date.xsl" />
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<catalog>
<xsl:for-each select="report/catalog[call/item[type='FLYTANDE' or type='HEMLAN']]">
<xsl:sort select="call/item/library"/>
<xsl:sort select="call/callNumber"/>
<xsl:sort select="marc/marcEntry[@tag='100']"/>
<xsl:sort select="marc/marcEntry[@tag='245']"/>
<xsl:if test="call/item/intervalCheckouts = 0 and call/item/intervalRenewals = 0">
<!--Here I want a second if.
If today minus lastUsed is greater than five years
-->
<itemline>
<yearOfPublication><xsl:value-of select="yearOfPublication"/></yearOfPublication>
<Author><xsl:value-of select="marc/marcEntry[@tag='100']"/></Author>
<Title><xsl:value-of select="substring(marc/marcEntry[@tag='245'],1,30)"/></Title>
<callNumber><xsl:text>"</xsl:text><xsl:value-of select="string(call/callNumber)"/><xsl:text>"</xsl:text></callNumber>
<library><xsl:value-of select="call/item/library"/></library>
<itemID><xsl:value-of select="call/item/itemID"/></itemID>
<type><xsl:value-of select="call/item/type"/></type>
<location><xsl:value-of select="call/item/location"/></location>
<totalCharges><xsl:value-of select="call/item/totalCharges"/></totalCharges>
<itemCreated><xsl:value-of select="call/item/dateCreated"/></itemCreated>
<dateLastUsed><xsl:value-of select="call/item/dateLastUsed"/></dateLastUsed>
<today><xsl:value-of select="substring(//report/dateCreated,1,10)"/></today>
<!--
Here I want a duration: today minus lastUsed as Years - months - days
-->
</itemline>
</xsl:if>
</xsl:for-each>
</catalog>
</xsl:template>
</xsl:stylesheet>