Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 4.50 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-30-2003, 09:01 AM   PM User | #1
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
<xs:element name="date" type="xs:date"/>

I need a schema with a type date with this format = day/month/year

mx xsd

<xs:element name="date" type="xs:date"/>


and my xml

<date>29/01/2003</date>


how can I do it ?

thank you
angiras is offline   Reply With Quote
Old 02-01-2003, 05:46 AM   PM User | #2
BrainJar
Regular Coder

 
Join Date: Jun 2002
Posts: 185
Thanks: 0
Thanked 0 Times in 0 Posts
BrainJar is an unknown quantity at this point
You can't, the date type in XML Schema is fixed. The only format allowed is YYYY-MM-DD (optionally preceeded with a minus sign and followed by a time zone).

The point of doing that is so you don't have to worry about different conventions like dd/mm/yy or mm/dd/yy. If an XML document follows the schema specification, any application program that processes it will know exactly what to expect. The application can then convert it to some other format.
BrainJar is offline   Reply With Quote
Old 02-01-2003, 08:26 AM   PM User | #3
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
ok

yes it is practicle to have this universal format , otherwise one get an headhake with countries dates

thank you
angiras is offline   Reply With Quote
Old 02-01-2003, 08:43 AM   PM User | #4
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
format

it works , but how can I format it with xslt ?

XML =

<date>2003-02-01</date>

XSLT =

<xsl:if test="date/text()">
<div class="date">
<xsl:value-of select="date"/>
</div>
</xsl:if>


to get HTML =

<div class="date">01/02/2003</div>


thank you
angiras is offline   Reply With Quote
Old 02-01-2003, 07:38 PM   PM User | #5
BrainJar
Regular Coder

 
Join Date: Jun 2002
Posts: 185
Thanks: 0
Thanked 0 Times in 0 Posts
BrainJar is an unknown quantity at this point
You can use the substring() function:

<xsl:template match="date">
&nbsp;&nbsp;<div>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:attribute name="class">date</xsl:attribute>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:value-of select="substring(text(), 9, 2)"/>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:text>/</xsl:text>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:value-of select="substring(text(), 6, 2)"/>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:text>/</xsl:text>
&nbsp;&nbsp;&nbsp;&nbsp;<xsl:value-of select="substring(text(), 1, 4)"/>
&nbsp;&nbsp;</div>
</xsl:template>

One word of caution, xs:date does allow more than four digits for the year, and an optional minus sign, so -1000000-02-14 (one millions years B.C.) is a valid xs:date and the above would not work. But you can always define your schema to force the date to fall within a specific range. For example:

<xs:element name="date">
&nbsp;&nbsp;<xs:simpleType>
&nbsp;&nbsp;&nbsp;&nbsp;<xs:restriction base="xs:date">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<xs:minInclusive value="0001-01-01"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<xs:maxInclusive value="9999-12-31"/>
&nbsp;&nbsp;&nbsp;&nbsp;</xs:restriction>
&nbsp;&nbsp;</xs:simpleType>
</xs:element>

Last edited by BrainJar; 02-01-2003 at 07:41 PM..
BrainJar is offline   Reply With Quote
Old 02-01-2003, 10:13 PM   PM User | #6
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
super !

then I have done:


XSD =

<xs:element name="date">
<xs:simpleType>
<xs:restriction base="xs:date">
<xs:minInclusive value="2003-01-01"/>
<xs:maxInclusive value="2010-01-01"/>
</xs:restriction>
</xs:simpleType>
</xs:element>


XSLT =

<xsl:if test="date/text()">
<div class="date">
<xsl:attribute name="class">date</xsl:attribute>
<xsl:value-of select="substring(text(), 9, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(text(), 6, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(text(), 1, 4)"/>
</div>
</xsl:if>


and I get HTML =


//


:-(( I think I've done something wrong
angiras is offline   Reply With Quote
Old 02-01-2003, 10:20 PM   PM User | #7
angiras
Regular Coder

 
Join Date: Dec 2002
Location: France
Posts: 522
Thanks: 0
Thanked 0 Times in 0 Posts
angiras is an unknown quantity at this point
it works

<xsl:if test="date/text()">
<div class="date">
<xsl:value-of select="substring(date, 9, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(date, 6, 2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring(date, 1, 4)"/>
</div>
</xsl:if>



It works !


thank you very much :-))
angiras is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:05 AM.


Advertisement
Log in to turn off these ads.