Hub Nexus
업데이트됨

작가아직 작성자가 없습니다맡기

개선할 점이 보이나요? 변경을 제안하세요.

후원

매거진 XForms · 137개 중 32번째 페이지

Motivation

XML stores dates in the format YYYY-MM-DD such as 2007-08-30. Unfortunately this is usually not the way users want to view their dates.

This example XForms program uses CSS to hide an input date and an XPath expression to get the date to display in the MM/DD/YYYY format typically used in the US.

Link to Date Format External Example

Sample Program

xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:d="http://www.mydata.com/xmlns/data">;

Demo of date formatting using XPath concat and substring.
type="text/css">
@namespace xf url('http://www.w3.org/2002/xforms');

.hidden .xf-value {
display:none;
}
]]>

xmlns="">

2006-09-12

nodeset="/MyModel/MyDate" type="xs:date" />

class="hidden" ref="/MyModel/MyDate" incremental="true">
Select Date:

value="concat(substring(/MyModel/MyDate,6,2),
'/',
substring(/MyModel/MyDate,9,2),
'/',
substring(/MyModel/MyDate,1,4))"
/>

Discussion

The CSS style sheet hides the input field. The input has the class="hidden" attribute.

The output is formatted using the following XPath expression:

concat(
substring(/MyModel/MyDate,6,2),
'/',
substring(/MyModel/MyDate,9,2),
'/',
substring(/MyModel/MyDate,1,4)
)

Concat is the XPath concatenation operator.
The input is in the format: "YYYY-MM-DD". We just need to reach in and get the correct characters out.

  • The first substring goes to the 6th character and pulls out the two month (MM) characters.
  • The second substring starts at the 9th character and gets two day (DD) characters.
  • The last substring returns characters 1-4 which are the four year characters (YYYY).

You do not have to display all four letters in the year. By changing the last substring from:

substring(/MyModel/MyDate,1,4)

to be

substring(/MyModel/MyDate,3,4)

You will only get the last two digits of the year.

Where this page came from

This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

이 페이지가 속한 매거진XForms

언어English

이용 허락: CC BY-SA 4.0 · 출처 en.wikibooks.org

1

0

0

0

Spinner Logo

코멘트

Spinner Logo
버전: 2CC0 1.0 — public domain
The runaway star that left the Tarantula Nebula
버전: 2CC0 1.0 — public domain
The Blackwell School, where segregation had no law behind it
버전: 2CC0 1.0 — public domain
The Eagle Nebula, seen in the infrared
버전: 2CC0 1.0 — public domain
The house where the Equal Rights Amendment was written
버전: 2CC0 1.0 — public domain
The Aleutians, the forgotten front of the Second World War
버전: 2CC0 1.0 — public domain
The Cosmic Cliffs are not cliffs