我有一個關於XSLT 2.0轉換和分析串組成的一個問題:如何在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})$
表達式提取兩組。第一組包含日期,第二組包含時間,我想像樣式表中那樣添加它們。
現在發生的事情是,只有不匹配的子串塊被執行,而不是匹配子串塊。我也試過用xsl when元素和那裏的匹配作品,但它不是我想要做的方式,而且我想使用regex-group()
函數,因爲它完全符合我的需求。
我找不到我可能在這裏完成的錯誤。先謝謝你!
請張貼最小但完整的XML輸入樣本來演示該問題。 –