XSLT:用当前日期和时间替换XML值



我有以下XML文档:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
    <Elaborations>
        <Elaboration>
            <DateBegin>2014-01-01T02:00:00.000+01:00</DateBegin>
            <DateEnd>2014-01-01T02:00:00.000+01:00</DateEnd>
            <Result>12594</Result>
        </Elaboration>
        <Elaboration>
            <DateBegin>2014-01-01T02:00:00.000+01:00</DateBegin>
            <DateEnd>2014-01-01T02:00:00.000+01:00</DateEnd>
            <Result>12593</Result>
        </Elaboration>
        <Elaboration>
            <DateBegin>2014-01-01T02:00:00.000+01:00</DateBegin>
            <DateEnd>2014-01-01T02:00:00.000+01:00</DateEnd>
            <Result>12595</Result>
        </Elaboration>
        <Elaboration>
            <DateBegin>2014-01-01T02:00:00.000+01:00</DateBegin>
            <DateEnd>2014-01-01T02:00:00.000+01:00</DateEnd>
            <Result>29598</Result>
        </Elaboration>
        <Elaboration>
            <DateBegin>2014-01-01T02:00:00.000+01:00</DateBegin>
            <DateEnd>2014-01-01T02:00:00.000+01:00</DateEnd>
            <Result>37583</Result>
        </Elaboration>
    </Elaborations>
</soapenv:Body>
</soapenv:Envelope>

我想用XSLT将元素DateBegin和DateEnd的值替换为当前日期和时间。我写了以下转换:

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:variable name="dateNow" select="current-dateTime()"/>
    <xsl:template match="DateBegin/text()">
        <xsl:value-of select="$dateNow"/>
    </xsl:template>
    <xsl:template match="DateEnd/text()">
        <xsl:value-of select="$dateNow"/>
    </xsl:template>
</xsl:stylesheet>

但是我在XSLT文档上遇到了一个解析错误。问题出在哪里?

我解决了在类路径中包含camel-saxon的问题。这最终启用了xslt 2.0函数(如当前日期时间)的使用。

最新更新