[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Xpath patern question

Subject: RE: Xpath patern question
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Mar 2003 18:09:51 -0000
patern
Hi Helder.

Try this:
<xsl:template match="date">
 <!-- this will remove spaces and lf. It also translates '-' to '/' so
you can use only one test -->
 <xsl:variable name="dt" select="translate(normalize-space(.),'-
','/')"/>
 <!-- the date format used is: dd/mm/yyyy -->
 <!-- the day is easy :) -->
 <xsl:variable name="d" select="substring-before($dt,'/')"/>
 <!-- the month is like the day but we'll have to extract first the
'dd/' part -->
 <xsl:variable name="m"
select="substring-before(substring($dt,string-length($d) + 2),'/')"/>
 <!-- to extract the year we can use the same method used for the month
but with substring-after -->
 <xsl:variable name="a"
select="substring-after(substring($dt,string-length($d) + 2),'/')"/>
 <!-- this is just for display the values, here you'll have the tree
variable $d = day, $m = month and $a = year -->
  <Data>
   <Dia><xsl:value-of select="$d"/></Dia>
   <Mes><xsl:value-of select="$m"/></Mes>
   <Ano><xsl:value-of select="$a"/></Ano>
  </Data>
 </xsl:template>

This template works with the following xml, you'll have to change It to
your needs
<doc>
 <date>1/1/2002</date>
 <date>10/12/2003</date>
 <date>12/3/2001</date>
</doc>

Hope that this helps you

> -----Mensagem original-----
> De: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] Em nome de Hélder Sousa
> Enviada: segunda-feira, 10 de Março de 2003 17:35
> Para: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Assunto: RE:  Xpath patern question
> 
> 
> I had think about that solution but my date can be like 
> "1/1/2003" and I can't change it to " 1/ 1/2003".. So that 
> doesn't work. I can put some more conditions in [...] but in 
> this case it's better to use the script.. The regular 
> expression would be the best way.. Tks anyway :)
> 
> 
(...)
 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.