docbook-apps

  • 1.  Date and Time normalization

    Posted 12-03-2012 18:53


    I want to "normalize" some dates in my DocBook.

    Ie I have dates written in a number of different formats (eg 3/12/2012, 3 Dec 2012, 3 December 2012) which I'd like to normalize into one.

    This is sometimes just to achieve consistency in the output documents - ie to make them the same as my existing ones, written in Word, despite their starting out in a number of different formats. Though in one particular case, epub3, it is to get the dates into the format required by the spec. Epub requires dates in a particular format, and the existing eupb3 stylesheets just pass dates through as found in the source (and I have known it to leave duplicates, though I may have tweaked one of my source files to fix this as it isn't happening with my test file right now).



    I'm expecting to do this by using a standard function to parse the dates as strings, then to use a formatting function to get the resultant date/time into a chosen format.

    I can't see an XSLT 1 function to do this but I think there's one in EXSLT.

    Can anyone advise on the best option to use. Or direct me to any other options available.





    Regards,

    Richard.












    [Blue line]
    Richard Kerry
    BNCS Engineer
    T: +44 (0)20 82259063
    M: +44 (0)7812 325518
    Room EBX 301, BBC Television Centre, Wood Lane, London, W12 7RJ
    richard.kerry@atos.net<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net>
    uk.atos.net<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=http%3a%2f%2fuk.atos.net%2fen-uk%2f>
    [Atos logo]
    This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.



  • 2.  Re: [docbook-apps] Date and Time normalization

    Posted 12-03-2012 20:20
    Hi Richard,
    EXSLT does have some date-time functions, including one that will generate the current date and time in a standard format. Perhaps the most useful function for you will be date-format() to convert a standard date string into some other output format.

    But EXSLT does not include a function to parse an arbitrary string into a standard date string. That is actual a hard problem with ambiguities that must be resolved, such as "Is 3/12/2012 to be interpreted as March 12 or December 3?". And month names and abbreviations come in many languages and abbreviation styles. I have not been able to find an XSLT module that can handle such conversions. If you find something, please let me know and I will add it to the DocBook epub3 stylesheet.

    The standard xs:date string format is CCYY-MM-DD. If you can get your data into that format, then the EXSLT date functions can process it.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net


    From: Kerry, Richard
    Sent: Monday, December 03, 2012 10:52 AM
    To: DocBook Apps Mailing List ?[docbook-apps@lists.oasis-open.org]?
    Subject: [docbook-apps] Date and Time normalization




    I want to "normalize" some dates in my DocBook.

    Ie I have dates written in a number of different formats (eg 3/12/2012, 3 Dec 2012, 3 December 2012) which I'd like to normalize into one.

    This is sometimes just to achieve consistency in the output documents - ie to make them the same as my existing ones, written in Word, despite their starting out in a number of different formats. Though in one particular case, epub3, it is to get the dates into the format required by the spec. Epub requires dates in a particular format, and the existing eupb3 stylesheets just pass dates through as found in the source (and I have known it to leave duplicates, though I may have tweaked one of my source files to fix this as it isn't happening with my test file right now).



    I'm expecting to do this by using a standard function to parse the dates as strings, then to use a formatting function to get the resultant date/time into a chosen format.

    I can't see an XSLT 1 function to do this but I think there's one in EXSLT.

    Can anyone advise on the best option to use. Or direct me to any other options available.





    Regards,

    Richard.














    Richard Kerry

    BNCS Engineer


    T: +44 (0)20 82259063

    M: +44 (0)7812 325518

    Room EBX 301, BBC Television Centre, Wood Lane, London, W12 7RJ

    richard.kerry@atos.net

    uk.atos.net







    This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.



    --------------------------------------------------------------------------------



    ---------------------------------------------------------------------
    To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org
    For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org


  • 3.  RE: [docbook-apps] Date and Time normalization

    Posted 12-04-2012 11:54

    Bob,

    Thanks for the notes about dates and EXSLT.

    Note that I am not dealing with arbitrary date formats. I am dealing with a small number; not many more than the three I listed below (*). Also that they are all UK standard, ie 3/12 is definitely 3rd December. And the month names are English, and usually either three letter abbreviations or in full.

    In a previous job many years ago we did have, written in Pascal, a fairly arbitrary date parser. It could cope with relative ones like "tomorrow" and "next tuesday" as well as the more obvious (absolute) ones. It was used interactively so these relative forms were useful. The general technique was to check a number of Regular Expressions until one matched. I know XSLT 1 doesn't have REs so that may be harder here, but if it can parse based on an expected format, and return a failure, then I should be able to scan through several for a match.

    I'll do some more work on this when I am next able to.
    If I get something that's applicable to the epub3 stylesheets I'll let you know.


    Appreciatively,
    Richard.

    (*)
    [0]3/12/12
    [0]3/12/2012
    [0]3-12-2012
    [0]3 Dec 12
    [0]3 December 2012
    (possibly) 20121203

    so mainly variants of "\d{1,2}[/:]\d{1,2}[/:]\d{1,4}" or "\d{1,2} [a-zA-Z]{3,9} \d{1,4}"


    ________________________________
    From: Bob Stayton [mailto:bobs@sagehill.net]
    Sent: 03 December 2012 20:20
    To: Kerry, Richard; docbook-apps@lists.oasis-open.org
    Subject: Re: [docbook-apps] Date and Time normalization

    Hi Richard,
    EXSLT does have some date-time functions, including one that will generate the current date and time in a standard format. Perhaps the most useful function for you will be date-format() to convert a standard date string into some other output format.

    But EXSLT does not include a function to parse an arbitrary string into a standard date string. That is actual a hard problem with ambiguities that must be resolved, such as "Is 3/12/2012 to be interpreted as March 12 or December 3?". And month names and abbreviations come in many languages and abbreviation styles. I have not been able to find an XSLT module that can handle such conversions. If you find something, please let me know and I will add it to the DocBook epub3 stylesheet.

    The standard xs:date string format is CCYY-MM-DD. If you can get your data into that format, then the EXSLT date functions can process it.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net<mailto:bobs@sagehill.net>

    From: Kerry, Richard<mailto:richard.kerry@atos.net>
    Sent: Monday, December 03, 2012 10:52 AM
    To: DocBook Apps Mailing List ?[docbook-apps@lists.oasis-open.org]?<mailto:docbook-apps@lists.oasis-open.org]?>
    Subject: [docbook-apps] Date and Time normalization




    I want to "normalize" some dates in my DocBook.

    Ie I have dates written in a number of different formats (eg 3/12/2012, 3 Dec 2012, 3 December 2012) which I'd like to normalize into one.

    This is sometimes just to achieve consistency in the output documents - ie to make them the same as my existing ones, written in Word, despite their starting out in a number of different formats. Though in one particular case, epub3, it is to get the dates into the format required by the spec. Epub requires dates in a particular format, and the existing eupb3 stylesheets just pass dates through as found in the source (and I have known it to leave duplicates, though I may have tweaked one of my source files to fix this as it isn't happening with my test file right now).



    I'm expecting to do this by using a standard function to parse the dates as strings, then to use a formatting function to get the resultant date/time into a chosen format.

    I can't see an XSLT 1 function to do this but I think there's one in EXSLT.

    Can anyone advise on the best option to use. Or direct me to any other options available.





    Regards,

    Richard.












    Richard Kerry
    BNCS Engineer
    T: +44 (0)20 82259063
    M: +44 (0)7812 325518
    Room EBX 301, BBC Television Centre, Wood Lane, London, W12 7RJ
    richard.kerry@atos.net<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=mailto%3arichard.kerry%40atos.net>
    uk.atos.net<https://webmail.siemens-it-solutions.com/owa/redir.aspx?C=9fb20d019e3e4cb99344d708709a3177&URL=http%3a%2f%2fuk.atos.net%2fen-uk%2f>
    This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted.

    ________________________________

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org
    For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org