Regular Expression's Jungle

View: New views
2 Messages — Rating Filter:   Alert me  

Regular Expression's Jungle

by saqi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I want to add some regular expression; when i get some data in any other format just convert it to my own. like if i have a date like 02/23/2008 then convert it to 02-23-2008. i have surfed the web but cannot find any simple example that can fit in. I found many complex examples all the way, which just passed over me...lolz. Is there any simple example available or help through which i can understand the basic working of regex, and can define my own regular expressions.
Thanks
Regards,
Saqib Javed

Re: Regular Expression's Jungle

by sonika_nitj :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi...
I have also faced same problem.
See what I have used for formatting a date from one format to other:
<fo:inline>
        <xsl:variable name="formattedIssueDate"  select="java:parse(java:java.text.SimpleDateFormat.new('yyyy-MM-dd HH:mm:ss.SSS' ), //IssueDate)" />
        <xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('MM/dd/yyyy' ), $formattedIssueDate)" />
</fo:inline>

What you have to do is the following:
        <xsl:variable name="formattedIssueDate"  select="java:parse(java:java.text.SimpleDateFormat.new('MM/dd/yyyy' ), //IssueDate)" />
        <xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('MM-dd-yyyy' ), $formattedIssueDate)" />

Note that the Date format you provide in SimpleDateFormat constructor should be a proper date format.
And the java namespace should be added to your style sheet
 as follows:
<xsl:stylesheet version="1.1"
        xmlns:java="http://xml.apache.org/xslt/java"
        exclude-result-prefixes="java"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:fo="http://www.w3.org/1999/XSL/Format">

-Sonika
saqi wrote:
Hello,
I want to add some regular expression; when i get some data in any other
format just convert it to my own. like if i have a date like 02/23/2008 then
convert it to 02-23-2008. i have surfed the web but cannot find any simple
example that can fit in. I found many complex examples all the way, which
just passed over me...lolz. Is there any simple example available or help
through which i can understand the basic working of regex, and can define my
own regular expressions.
Thanks
Regards,
Saqib Javed