问题描述
首先,我使用 XSLT 2.0 和 SAXON-HE 9.5.1.5.
First of all, I am using XSLT 2.0 with SAXON-HE 9.5.1.5.
以下命令是否还有其他选择?
Is there any alternative of the following command?
<xsl:mode on-no-match="shallow-copy"/>
在我输入的 XML 中,有一个时间字段将以 HH:MM 格式出现.我想添加这个,结果格式也只能是 HH:MM 格式.
In my input XML, there is a field of time which will be coming as HH:MM format. I want to add this and the resultant format will also be in HH:MM format only.
输入 XML
<Root>
<Detail>
<Time>24:00</Time>
<Detail>
<Detail>
<Time>59:10</Time>
<Detail>
<Detail>
<Time>4:59</Time>
<Detail>
<Detail>
<Time></Time>
<Detail>
<Detail>
<Detail>
<Root>
希望得到快速帮助.
推荐答案
定义在 https://www.w3.org/TR/xslt-30/#built-in-templates-shallow-copy,基本上,对于单个未命名的模式,您可以在 XSLT 2 或 1 中替换它,其中您不使用身份转换进行流式传输(另请参见 https://www.w3.org/TR/xslt20/#shallow-copy) 模板:
The <xsl:mode on-no-match="shallow-copy"/>
is defined in https://www.w3.org/TR/xslt-30/#built-in-templates-shallow-copy, basically, for a single, unnamed mode you can replace it in XSLT 2 or 1 where you don't do streaming with the identity transformation (see also https://www.w3.org/TR/xslt20/#shallow-copy) template:
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
至于格式化从转换为 XSLT 2 中的 xs:dayTimeDuration
s 的时间值总和计算的持续时间,我认为
As for formatting a duration computed from the sum of your time values converted to xs:dayTimeDuration
s in XSLT 2, I think
<xsl:function name="mf:format-duration" as="xs:string">
<xsl:param name="duration" as="xs:dayTimeDuration"/>
<xsl:sequence select="concat(format-number(xs:integer(floor($duration div xs:dayTimeDuration('PT1H'))), '00'), ':', format-number(minutes-from-duration($duration), '00'))"/>
</xsl:function>
这样做.
http://xsltransform.hikmatu.com/nc4NzPS 上的在线示例.
请注意,您的原始输入样本有空的 Hours
元素,要处理它们,需要一些额外的规范来将它们转换为时间或持续时间,并且需要实现.
Note that your original input sample had empty Hours
elements, to treat them some additional spec on how to convert them to a time or duration is needed and needs to be implemented.
这篇关于XSLT 2.0:添加时间和开启匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!