Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/07/2007, 06:20
Kimppa
 
Fecha de Ingreso: julio-2007
Mensajes: 22
Antigüedad: 17 años, 4 meses
Puntos: 0
Formato de fechas en XSL

Hola a tod@s; soy nueva en el foro y tengo un problemilla que me gustaria que me ayudarais a solucionar, lo voy a explicar un poco:
Estoy haciendo un programa en xsl de conversion de fechas. Mi fecha esta en %Y%m%d (2007-07-24) y kiero que me aparezca asi--> 24 de julio de 2007.
El programa que estoy haciendo es este:

Cita:
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
xmlns:dt="http://xsltsl.org/date-time"
xmlns:str="http://xsltsl.org/string"
extension-element-prefixes="doc str">


<xsl:call-template name="dt:format-date-time">
<xsl:with-param name="xsd-date-time" select="pubDate"/>
</xsl:call-template>



<xsl:template name="dt:format-date-time">

<xsl:param name='xsd-date-time'/>
<xsl:param name='year'/>
<xsl:param name='month'/>
<xsl:param name='day'/>
<xsl:param name='format' select="'%d de %B de %Y'"/>


<xsl:value-of select="substring-before($format, '%')"/>

<xsl:variable name="code" select="substring(substring-after($format, '%'), 1, 1)"/>

<xsl:choose>

<xsl:when test='$xsd-date-time'>
<xsl:call-template name='dt:format-date-time'>
<xsl:with-param name='year'>
<xsl:call-template name='dt:get-xsd-datetime-year'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='month'>
<xsl:call-template name='dt:get-xsd-datetime-month'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='day'>
<xsl:call-template name='dt:get-xsd-datetime-day'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='hour'>
<xsl:call-template name='dt:get-xsd-datetime-hour'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='minute'>
<xsl:call-template name='dt:get-xsd-datetime-minute'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='time-zone'>
<xsl:call-template name='dt:get-xsd-datetime-timezone'>
<xsl:with-param name='xsd-date-time' select='$xsd-date-time'/>
</xsl:call-template>
</xsl:with-param>

<xsl:with-param name='format'>
<xsl:choose>
<xsl:when test='contains($format, "%")'>
<xsl:text>%</xsl:text>
<xsl:value-of select='substring-after($format, "%")'/>
</xsl:when>

<xsl:otherwise>
<xsl:value-of select='$format'/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>

</xsl:call-template>
</xsl:when>

<!-- Full month name -->
<xsl:when test="$code='B'">
<xsl:call-template name="dt:get-month-name">
<xsl:with-param name="month" select="$month"/>
</xsl:call-template>
</xsl:when>

<!-- Month as decimal number (01 - 12) -->
<xsl:when test="$code='m'">
<xsl:if test="$month &lt; 10">0</xsl:if>
<xsl:value-of select="number($month)"/>
</xsl:when>

<!-- Day of month as decimal number (01 - 31) -->
<xsl:when test="$code='d'">
<xsl:if test="$day &lt; 10">0</xsl:if>
<xsl:value-of select="number($day)"/>
</xsl:when>

<!-- Year with century, as decimal number -->
<xsl:when test="$code='Y'">
<xsl:value-of select="concat(substring('000', string-length(number($year))), $year)"/>
</xsl:when>

<!-- Percent sign -->
<xsl:when test="$code='%'">
<xsl:text>%</xsl:text>
</xsl:when>

</xsl:choose>

<xsl:variable name="remainder" select="substring(substring-after($format, '%'), 2)"/>

<xsl:if test="not($xsd-date-time) and $remainder">
<xsl:call-template name="dt:format-date-time">
<xsl:with-param name="year" select="$year"/>
<xsl:with-param name="month" select="$month"/>
<xsl:with-param name="day" select="$day"/>
<xsl:with-param name="hour" select="$hour"/>
<xsl:with-param name="minute" select="$minute"/>
<xsl:with-param name="time-zone" select="$time-zone"/>
<xsl:with-param name="format" select="$remainder"/>
</xsl:call-template>
</xsl:if>

</xsl:template>



<xsl:template name="dt:get-month-name">
<xsl:param name="month"/>

<xsl:choose>
<xsl:when test="$month = 1">Enero</xsl:when>
<xsl:when test="$month = 2">Febrero</xsl:when>
<xsl:when test="$month = 3">Marzo</xsl:when>
<xsl:when test="$month = 4">Abril</xsl:when>
<xsl:when test="$month = 5">Mayo</xsl:when>
<xsl:when test="$month = 6">Junio</xsl:when>
<xsl:when test="$month = 7">Julio</xsl:when>
<xsl:when test="$month = 8">Agosto</xsl:when>
<xsl:when test="$month = 9">Septiembre</xsl:when>
<xsl:when test="$month = 10">Octubre</xsl:when>
<xsl:when test="$month = 11">Noviembre</xsl:when>
<xsl:when test="$month = 12">Diciembre</xsl:when>
<xsl:otherwise>error: <xsl:value-of select="$month"/></xsl:otherwise>
</xsl:choose>

</xsl:template>



<xsl:template name='dt:get-xsd-datetime-year'>
<xsl:param name='xsd-date-time'/>

<xsl:choose>
<xsl:when test='contains($xsd-date-time, "T")'>
<xsl:call-template name='dt:get-xsd-datetime-year'>
<xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
</xsl:call-template>
</xsl:when>

<!-- Check for time -->
<xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>

<xsl:otherwise>
<!-- This is a date -->
<xsl:value-of select='substring-before($xsd-date-time, "-")'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name='dt:get-xsd-datetime-month'>
<xsl:param name='xsd-date-time'/>

<xsl:choose>
<xsl:when test='contains($xsd-date-time, "T")'>
<xsl:call-template name='dt:get-xsd-datetime-month'>
<xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
</xsl:call-template>
</xsl:when>

<!-- Check for time -->
<xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>

<xsl:otherwise>
<!-- This is a date -->
<xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 1, 2)'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



<xsl:template name='dt:get-xsd-datetime-day'>
<xsl:param name='xsd-date-time'/>

<xsl:choose>
<xsl:when test='contains($xsd-date-time, "T")'>
<xsl:call-template name='dt:get-xsd-datetime-day'>
<xsl:with-param name='xsd-date-time' select='substring-before($xsd-date-time, "T")'/>
</xsl:call-template>
</xsl:when>

<!-- Check for time -->
<xsl:when test='substring($xsd-date-time, 3, 1) = ":"'/>

<xsl:otherwise>
<!-- This is a date -->
<xsl:value-of select='substring(substring-after($xsd-date-time, "-"), 4, 2)'/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
El xml es muy simple (estoy haciendo simplemente pruebas)

Cita:
<?xml version="1.0" encoding='ISO-8859-1'?>
<?xml-stylesheet href="USUA_date-time.xsl" type="text/xsl"?>

<item>
<pubdate>2007-07-24</pubdate>
</item>
No se si alguien me podra ayudar, pero de todas formas gracias, y no os asusteis si veis alguna burrada que me falta o asi, porque soy nueva en este tipo de lenguajes y estoy bastante perdida :p
Gracias de nuevo.