【发布时间】:2018-02-09 03:51:41
【问题描述】:
我有一个关于 xslt 2.0 转换和分析字符串组件的问题:
这是我迄今为止尝试过的:
<!-->Template for properties<-->
<xsl:template match="UserValue">
<xsl:variable name="TITLE" select="./@title"/>
<xsl:variable name="VALUE" select="./@value"/>
<xsl:analyze-string select="$VALUE" regex="^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})$">
<xsl:matching-substring>
<Property>
<Title><xsl:value-of select="$TITLE"/></Title>
<Value>Date:<xsl:value-of select="regex-group(1)"/>Time:<xsl:value-of select="regex-group(2)"/></Value>
</Property>
</xsl:matching-substring>
<xsl:non-matching-substring>
<!-->Set title and value property<-->
<Property>
<Title><xsl:value-of select="$TITLE"/></Title>
<Value><xsl:value-of select="$VALUE"/></Value>
</Property>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
有以下格式的日期时间字符串:YYYY-MM-DDTHH:MM:SS
我使用 ^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2})$ 表达式来提取两个组。第一组带有日期,第二组带有时间,我想像在样式表中一样添加它们。
现在发生的事情是,只有 non-matching-substring 块被执行,而不是 matching-substring 块。我还尝试使用 xsl when 元素和匹配工作,但这不是我想要的方式,而且我想使用 regex-group() 函数,因为它完全符合我的需求。
我在这里找不到我可能犯的错误。提前谢谢!
【问题讨论】:
-
请发布一个最小但完整的 XML 输入示例来演示问题。