我有一个看起来像这样的XML文件。 列表中的所有项目都有dateCreated。 已使用的项目具有dateLastUsed。 未使用的项目没有节点dateLastUsed。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="stripped.xsl"?>
<report>
<dateCreated>2016-05-20T12:16:11</dateCreated>
<catalog>
<description>Older than five, never used</description>
<call>
<item>
<itemID>30580004885005</itemID>
<dateCreated>2000-02-11</dateCreated>
</item>
</call>
</catalog>
<catalog>
<description>Older than five, but used threee years ago</description>
<call>
<item>
<dateLastUsed>2013-10-25</dateLastUsed>
<itemID>30580005522235</itemID>
<dateCreated>1996-06-20</dateCreated>
</item>
</call>
</catalog>
<catalog>
<description>Older than five, used more than five years ago</description>
<call>
<item>
<dateLastUsed>2010-04-12</dateLastUsed>
<itemID>30580004882085</itemID>
<dateCreated>2000-02-01</dateCreated>
</item>
</call>
</catalog>
<catalog>
<description>Older than five, but used this year</description>
<call>
<item>
<dateLastUsed>2016-05-18</dateLastUsed>
<itemID>30580004899105</itemID>
<dateCreated>2000-03-29</dateCreated>
</item>
</call>
</catalog>
<catalog>
<description>Younger than five, used less than five years ago</description>
<call>
<item>
<dateLastUsed>2016-04-12</dateLastUsed>
<itemID>30580005334920</itemID>
<dateCreated>2015-04-25</dateCreated>
</item>
</call>
</catalog>
<catalog>
<description>Younger than five, never used</description>
<call>
<item>
<itemID>30580005334938</itemID>
<dateCreated>2014-04-25</dateCreated>
</item>
</call>
</catalog>
</report>
我想过滤列表,因此它只包含项目 1)超过五年和 2a)五年多前使用或 2b)从未使用过
1很容易用if子句解决 2a也很容易用第二个if子句解决 - 但如何解决2b?
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="fiveYears" select="1825" />
<xsl:template match="/">
<catalog>
<xsl:for-each select="report/catalog">
<xsl:variable name="daysSinceCreated">
<xsl:call-template name="date-difference">
<xsl:with-param name="date1" select="call/item/dateCreated" />
<xsl:with-param name="date2" select="//report/dateCreated" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="daysSinceUsed">
<xsl:call-template name="date-difference">
<xsl:with-param name="date1" select="call/item/dateLastUsed" />
<xsl:with-param name="date2" select="//report/dateCreated" />
</xsl:call-template>
</xsl:variable>
<xsl:if test="$daysSinceCreated > $fiveYears">
<xsl:if test="$daysSinceUsed > $fiveYears">
<itemline>
<description><xsl:value-of select="description"/></description>
<dateCreated><xsl:value-of select="call/item/dateCreated"/></dateCreated>
<daysSinceCreated><xsl:value-of select="$daysSinceCreated"/></daysSinceCreated>
<dateLastUsed><xsl:value-of select="call/item/dateLastUsed"/></dateLastUsed>
<daysSinceUsed><xsl:value-of select="$daysSinceUsed"/></daysSinceUsed>
</itemline>
</xsl:if>
</xsl:if>
</xsl:for-each>
</catalog>
</xsl:template>
<xsl:template name="date-difference">
<xsl:param name="date1"/>
<xsl:param name="date2"/>
<xsl:param name="JDN1">
<xsl:call-template name="JDN">
<xsl:with-param name="date" select="$date1" />
</xsl:call-template>
</xsl:param>
<xsl:param name="JDN2">
<xsl:call-template name="JDN">
<xsl:with-param name="date" select="$date2" />
</xsl:call-template>
</xsl:param>
<xsl:value-of select="$JDN2 - $JDN1"/>
</xsl:template>
<xsl:template name="JDN">
<xsl:param name="date"/>
<xsl:param name="year" select="substring($date, 1, 4)"/>
<xsl:param name="month" select="substring($date, 6, 2)"/>
<xsl:param name="day" select="substring($date, 9, 2)"/>
<xsl:param name="a" select="floor((14 - $month) div 12)"/>
<xsl:param name="y" select="$year + 4800 - $a"/>
<xsl:param name="m" select="$month + 12*$a - 3"/>
<xsl:value-of select="$day + floor((153*$m + 2) div 5) + 365*$y + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045" />
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:1)
我会将你的[self addChildViewController:pageViewController];
pageViewController.view.frame = self.view.frame;
[self.view addSubview:pageViewController.view];
[pageViewController didMoveToParentViewController:self];
语句组合起来......
xsl:if
您也可以使用:<xsl:if test="($daysSinceCreated > $fiveYears and $daysSinceUsed > $fiveYears)
or not(string(call/item/dateLastUsed))">
<itemline>
<description><xsl:value-of select="description"/></description>
<dateCreated><xsl:value-of select="call/item/dateCreated"/></dateCreated>
<daysSinceCreated><xsl:value-of select="$daysSinceCreated"/></daysSinceCreated>
<dateLastUsed><xsl:value-of select="call/item/dateLastUsed"/></dateLastUsed>
<daysSinceUsed><xsl:value-of select="$daysSinceUsed"/></daysSinceUsed>
</itemline>
</xsl:if>
而不是检查or $daysSinceUsed='NaN'
的结果,因为即使没有使用string()
,您仍然在尝试计算$daysSinceUsed
。