|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Date Difference
Haarman, Michael wrote:
If you want your dates to have "dateness", XPath 2.0 is the way to go, and Mike H has shown the way forward. Here's an example that works with XSLT 1.0: date-diff.xsl:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/
Transform'>
<xsl:template match='dateRange'>
<diff>
<xsl:call-template name='diff'>
<xsl:with-param name='m1' select='substring-before(date[1],
"/")'/>
<xsl:with-param name='d1' select='substring-before(substring-
after(date[1], "/"), "/")'/>
<xsl:with-param name='y1' select='substring-after(substring-
after(date[1], "/"), "/")'/>
<xsl:with-param name='m2' select='substring-before(date[2],
"/")'/>
<xsl:with-param name='d2' select='substring-before(substring-
after(date[2], "/"), "/")'/>
<xsl:with-param name='y2' select='substring-after(substring-
after(date[2], "/"), "/")'/>
</xsl:call-template>
</diff>
</xsl:template>
<xsl:template name='diff'>
<xsl:param name='m1'/>
<xsl:param name='d1'/>
<xsl:param name='y1'/>
<xsl:param name='m2'/>
<xsl:param name='d2'/>
<xsl:param name='y2'/>
<xsl:value-of select='(number($d1) + number(document("days.xml")/
days/year[@name=$y1]/month[$m1]) + number(document("days.xml")/days/
year[@name=$y1]/@offset)) - (number($d2) + number(document
("days.xml")/days/year[@name=$y2]/month[$m2]) + number(document
("days.xml")/days/year[@name=$y2]/@offset))'/>
</xsl:template>
</xsl:stylesheet>days.xml:
<days>
<year name='2004' offset='12419'>
<month>31</month>
<month>29</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>30</month>
<month>31</month>
</year>
<year name='2005' offset='12784'>
<month>31</month>
<month>28</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>31</month>
<month>30</month>
<month>31</month>
<month>30</month>
<month>31</month>
</year>
</days>You can of course generate days.xml dynamically. -- g , Chris Burdess "They that can give up essential liberty to obtain a little safety deserve neither liberty nor safety." - Benjamin Franklin
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








