Subject: RE: Searching for specific character in string and outputting first 4 digits that follow
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 9 Sep 2008 13:19:00 +0100
|
> I am trying to figure out how to search for the 2nd instance
> of a character in a string and then output only the first 4
> digits that follow this character. For the PubDate element, I
> want to find the 2nd instance of the back slash ("/") and
> then output the 4-digit year that follows this back slash.
Actually that's a forwards slash.
In
> the following example, I want to output "2008'.
>
> <PubDate>5/12/2008 3:13:14 PM</PubDate>
>
In XSLT 2.0
replace(PubDate, '^[0-9]*/[0-9]*/([0-9]*).*$', $1)
In XSLT 1.0 (or 2.0)
substring(substring-after(substring-after(PubDate, '/'), '/'), 1, 4)
Michael Kay
http://www.saxonica.com/
|