Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    <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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ok

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

    thank you

  • #4
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    185
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 08:41 PM.

  • #6
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #7
    Regular Coder
    Join Date
    Dec 2002
    Location
    France
    Posts
    522
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 :-))


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •