Skip to content

Commit 5bf7992

Browse files
committed
xsd:dateTime literal rendering as datetime-local moved to the server-side
1 parent cd7003a commit 5bf7992

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

  • src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/form.xsl

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,6 @@ WHERE
161161
<!-- TO-DO: move to a better place. Does not take effect if typeahead is reset -->
162162
<ixsl:set-property object="." name="autocomplete" select="'off'"/>
163163
</xsl:template>
164-
165-
<!-- inject datetime-local inputs (only if the input is visible) TO-DO: align structure of constructor and editing form controls -->
166-
<xsl:template match="input[not(@type = 'hidden')][@name = 'ol'][following-sibling::input[@name = 'lt'][@value = '&xsd;dateTime']] | input[@name = 'ol'][@value][../following-sibling::div/input[@name = 'lt'][@value = '&xsd;dateTime']]" mode="ldh:RenderRowForm" priority="2">
167-
<ixsl:set-attribute name="type" select="'datetime-local'"/>
168-
<ixsl:set-attribute name="step" select="'1'"/>
169-
170-
<xsl:if test="@value">
171-
<!-- adjust the datetime value to the implicit (user's) timezone and format it to make it a legal datetime-local value: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#value -->
172-
<xsl:variable name="datetime-local" select="format-dateTime(adjust-dateTime-to-timezone(xs:dateTime(@value)), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')" as="xs:string"/>
173-
<ixsl:set-attribute name="value" select="$datetime-local"/>
174-
</xsl:if>
175-
</xsl:template>
176164

177165
<!-- set focus on the first required input -->
178166
<xsl:template match="fieldset//div[contains-token(@class, 'required')][1]//input" mode="ldh:RenderRowForm" priority="1">
@@ -195,11 +183,15 @@ WHERE
195183
<ixsl:remove-attribute name="name"/>
196184
</xsl:template>
197185

198-
<!-- adjust datetime-local values to the implicit timezone -->
186+
<!-- append timezone to the datetime-local values -->
199187
<xsl:template match="input[@type = 'datetime-local'][ixsl:get(., 'value')]" mode="ldh:FormPreSubmit" priority="1">
200188
<!-- set the input type back to 'text' because 'datetime-local' does not accept the timezoned value -->
201189
<ixsl:set-attribute name="type" select="'text'"/>
202-
<ixsl:set-property name="value" select="string(adjust-dateTime-to-timezone(ixsl:get(., 'value')))" object="."/>
190+
191+
<xsl:variable name="timezone" select="ixsl:get(following-sibling::input[contains-token(@class, 'input-timezone')], 'value')" as="xs:string"/>
192+
<!--TO-DO: handle invalid timezone values -->
193+
<xsl:variable name="timezoned-value" select="xs:dateTime(ixsl:get(., 'value') || $timezone)" as="xs:dateTime"/>
194+
<ixsl:set-property name="value" select="$timezoned-value" object="."/>
203195
</xsl:template>
204196

205197
<xsl:template name="bs2:SignUpComplete">
@@ -469,7 +461,7 @@ WHERE
469461
<xsl:variable name="request-uri" select="ldh:href($ldt:base, ac:absolute-path(ldh:base-uri(.)), map{}, $action)" as="xs:anyURI"/>
470462

471463
<!-- pre-process form before submitting it -->
472-
<!-- <xsl:apply-templates select="." mode="ldh:FormPreSubmit"/> -->
464+
<xsl:apply-templates select="." mode="ldh:FormPreSubmit"/>
473465

474466
<xsl:choose>
475467
<!-- we need to handle multipart requests specially because of Saxon-JS 2 limitations: https://saxonica.plan.io/issues/4732 -->
@@ -515,6 +507,9 @@ WHERE
515507

516508
<ixsl:set-style name="cursor" select="'progress'" object="ixsl:page()//body"/>
517509

510+
<!-- pre-process form before submitting it -->
511+
<xsl:apply-templates select="." mode="ldh:FormPreSubmit"/>
512+
518513
<xsl:variable name="elements" select=".//input | .//textarea | .//select" as="element()*"/>
519514
<xsl:variable name="triples" select="ldh:parse-rdf-post($elements)" as="element()*"/>
520515
<!-- canonicalize XML in rdf:XMLLiterals -->

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/imports/default.xsl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ exclude-result-prefixes="#all"
11131113

11141114
<!-- real numbers -->
11151115

1116-
<xsl:template match="text()[../@rdf:datatype = '&xsd;float'] | text()[../@rdf:datatype = '&xsd;double']" priority="1" mode="xhtml:Input">
1116+
<xsl:template match="text()[../@rdf:datatype = '&xsd;float'] | text()[../@rdf:datatype = '&xsd;double']" mode="xhtml:Input" priority="1">
11171117
<xsl:param name="type" select="'text'" as="xs:string"/>
11181118
<xsl:param name="id" as="xs:string?"/>
11191119
<xsl:param name="class" as="xs:string?"/>
@@ -1135,6 +1135,36 @@ exclude-result-prefixes="#all"
11351135
</xsl:call-template>
11361136
</xsl:template>
11371137

1138+
<!-- datetimes -->
1139+
1140+
<xsl:template match="text()[../@rdf:datatype = '&xsd;dateTime'][. castable as xs:dateTime][../@rdf:datatype = '&xsd;dateTime']" mode="xhtml:Input" priority="1" >
1141+
<xsl:param name="type" select="'datetime-local'" as="xs:string"/>
1142+
<xsl:param name="id" as="xs:string?"/>
1143+
<xsl:param name="class" as="xs:string?"/>
1144+
<xsl:param name="disabled" select="false()" as="xs:boolean"/>
1145+
1146+
<xsl:call-template name="xhtml:Input">
1147+
<xsl:with-param name="name" select="'ol'"/>
1148+
<xsl:with-param name="type" select="'datetime-local'"/> <!-- TO-DO: what is passing $type? Cannot use it because the value is 'text' -->
1149+
<xsl:with-param name="id" select="$id"/>
1150+
<xsl:with-param name="class" select="$class"/>
1151+
<xsl:with-param name="disabled" select="$disabled"/>
1152+
<xsl:with-param name="value" select="format-dateTime(xs:dateTime(.), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')"/>
1153+
</xsl:call-template>
1154+
1155+
<xsl:call-template name="xhtml:Input">
1156+
<xsl:with-param name="type" select="'hidden'"/>
1157+
<xsl:with-param name="name" select="'lt'"/>
1158+
<xsl:with-param name="value" select="../@rdf:datatype"/>
1159+
</xsl:call-template>
1160+
1161+
<xsl:call-template name="xhtml:Input">
1162+
<xsl:with-param name="class" select="'input-mini input-timezone'"/>
1163+
<xsl:with-param name="type" select="'text'"/>
1164+
<xsl:with-param name="value" select="format-dateTime(xs:dateTime(.), '[Z]')"/>
1165+
</xsl:call-template>
1166+
</xsl:template>
1167+
11381168
<!-- XHTML CONTENT IDENTITY TRANSFORM -->
11391169

11401170
<xsl:template match="@* | node()" mode="ldh:XHTMLContent">

0 commit comments

Comments
 (0)