Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 14th, 2013, 06:41 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default How to Test For Dates Less Than a Certain Value

Hello,

I have a date element in my XML file.
For example:
Code:
        <DETAIL>
            <DETAILLINE>
                <SEQUENCE>000001</SEQUENCE>
                <DOS>
                    <MM>07</MM>
                    <DD>01</DD>
                    <YYYY>2011</YYYY>
                </DOS>
            </DETAILLINE>
            <DETAILLINE>
                <SEQUENCE>000002</SEQUENCE>
                <DOS>
                    <MM>01</MM>
                    <DD>01</DD>
                    <YYYY>2012</YYYY>
                </DOS>
            </DETAILLINE>
        </DETAIL>
I need to do something at the end after all the <DETAILLINE>s are processed. If I find any <DOS> that is less than 07/01/2011 then I need to print something.

My current code is the following but it's not working correctly as it will return true if ANY <YYYY> is less than 2012 and ANY <MM> is less than 07. I need it to return true if the position of the <YYYY> and the <MM> is the same.
Code:
<xsl:if test="/doc/EOB/DETAIL[descendant::DETAILLINE/DOS/YYYY[. &lt; '2012']] and /doc/EOB/DETAIL[descendant::DETAILLINE/DOS/MM[. &lt; '07']]" >
I was thinking of using the CONCAT function but am not sure of the syntax for this situation.

I'm working with XSLT 1.0.

Any help will be greatly appreciated!

Thanks,
Rita

Last edited by ritagr; March 14th, 2013 at 06:45 PM.. Reason: Need to add more information.
 
Old March 15th, 2013, 04:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Use number(concat(YYYY,MM,DD)) to convert to a number such as 20110107, then compare numerically.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 15th, 2013, 11:05 AM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default How to Test For Dates Less Than a Certain Value

Hi Michael,

Many thanks for your response.

I played round with it and finally got it to work by removing the "descendant::" parts in the line.

Code:
<xsl:if test="concat(/doc/EOB/DETAIL/DETAILLINE/DOS/YYYY, /doc/EOB/DETAIL/DETAILLINE/DOS/MM) &lt; '201107'">
Thanks,
Rita
 
Old March 15th, 2013, 11:27 AM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default How to Test For Dates Less Than a Certain Value

Oops - nope!

That didn't work either.
With my latest code I just got the first value.

With "descendant::DETAILLINE/DOS/YYYY" etc. it returned a whole bunch of characters. I used FirePath to check my return result.

I need to check all the DETAILLINEs DOS only.

Thanks,
Rita
 
Old March 15th, 2013, 12:50 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, I didn't read your code carefully enough to work out where your conceptual misunderstandings lie.

You want

Code:
<xsl:if test="/doc/EOB/DETAIL/DETAILLINE/DOS[number(concat(YYYY,MM)) &lt; 201107]">
Read that as "if there is a /doc/EOB/DETAIL/DETAILLINE/DOS such that number(concat(YYYY,MM)) &lt; 201107 then...

wheras your version, with XPath 1.0, concatenates the first selected YYYY and the first selected MM and tests that.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
ritagr (March 15th, 2013)
 
Old March 15th, 2013, 01:13 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default How to Test For Dates Less Than a Certain Value

Hi Michael,

Yes, that was it exactly - XSLT 1.0 just checked the first concatenation.
Your code example worked perfectly!

Thank you so much for your help - much appreciated!

Rita





Similar Threads
Thread Thread Starter Forum Replies Last Post
transition between Test, Bug, Test drodriguez BOOK: Professional Scrum with Team Foundation Server 2010 1 November 11th, 2011 05:35 AM
test flyfish SQL Server DTS 0 January 13th, 2006 08:35 PM
test jdtaylor BOOK: Access 2003 VBA Programmer's Reference 0 December 30th, 2005 12:36 PM
test kristina Crystal Reports 0 June 14th, 2005 12:41 PM
test drarem Access 2 March 2nd, 2004 04:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.