Retroceder   Foros del Web > Diseño de Sitios web > Web general

Respuesta
 
Herramientas Desplegado
Antiguo 24-jul-2007, 07:20   #1 (permalink)
Kimppa no se puede cailificar en este momento
 
Fecha de Ingreso: julio-2007
Mensajes: 18
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.
Kimppa está desconectado   Responder Citando
Antiguo 25-jul-2007, 04:17   #2 (permalink)
Kimppa no se puede cailificar en este momento
 
Fecha de Ingreso: julio-2007
Mensajes: 18
Re: Formato de fechas en XSL

He ido eliminando cosas hasta que me ha quedado algo asi:
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: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="%B"/>


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

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

<xsl:choose>

<xsl:when test='$xsd-date-time'>
<xsl:call-template name='dt:format-date-time'>

<xsl:with-param name='year'>2007</xsl:with-param>
<xsl:with-param name='month'>11</xsl:with-param>
<xsl:with-param name='day'>24</xsl:with-param>

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

<xsl:otherwise>
<xsl:value-of select='B'/>
</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="11"/>
</xsl:call-template>
</xsl:when>

</xsl:choose>

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

<xsl:if test="not($xsd-date-time) and $remainder">
<xsl:call-template name="dt:format-date-time">
<xsl:with-param name="year" select="2007"/>
<xsl:with-param name="month" select="11"/>
<xsl:with-param name="day" select="24"/>
<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" select="11"/>

<xsl:choose>
<xsl:when test="$month=01">Enero</xsl:when>
<xsl:when test="$month=02">Febrero</xsl:when>
<xsl:when test="$month=03">Marzo</xsl:when>
<xsl:when test="$month=04">Abril</xsl:when>
<xsl:when test="$month=05">Mayo</xsl:when>
<xsl:when test="$month=06">Junio</xsl:when>
<xsl:when test="$month=07">Julio</xsl:when>
<xsl:when test="$month=08">Agosto</xsl:when>
<xsl:when test="$month=09">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:stylesheet>

La cosa es que me saca en pantalla todos los meses y yo solo quiero que me saque el que corresonda al numero que le mando (ejemplo: 11->noviembre)
Alguien que me eche una mano¿?
Kimppa está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 21:14.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96