-2

format-dateTime()関数内で日付計算を行い、XSL変換を行いたいと思います。これが私のXSLファイルです

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://www.abc.com/ws/integration/toolkit/2005/07" xmlns:fct="http://www.taleo.com/xsl_functions" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="ns:field[@name = 'EndDate']">
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:value-of select="fct:format-considering-timezone(xs:dateTime(.))"/>
    </xsl:copy>
</xsl:template>
<xsl:function name="fct:format-considering-timezone">
    <xsl:param name="dateTime" as="xs:dateTime"/>
    <xsl:variable name="dst">
        <xsl:value-of select="fct:get-timezone($dateTime)"/>
    </xsl:variable>
    <xsl:variable name="date-format">
        <xsl:choose>
            <xsl:when test="$dst = 'PT11H'">[Y,4-4]-[M,2-2]-[D,2-2]02:00:00T-05:00</xsl:when>
            <xsl:otherwise>[Y,4-4]-[M,2-2]-[D,2-2]00:00:00T-05:00</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>               
    <xsl:variable name="Duration">
        <xsl:choose>
            <xsl:when test="ns:field[@name='CareerSiteNo3'] = 'xyz'">P2D</xsl:when>
            <xsl:otherwise>P14D</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="AUTime">
        <xsl:value-of select="adjust-dateTime-to-timezone($dateTime + xs:dayTimeDuration($Duration), $dst)"/>
    </xsl:variable>
    <xsl:value-of select="format-dateTime((xs:datetime($AUTime) + xs:dayTimeDuration($Duration)), $date-format)"/>
</xsl:function>
<xsl:function name="fct:get-timezone" as="xs:dayTimeDuration">
    <xsl:param name="dateTime" as="xs:dateTime"/>
    <xsl:variable name="timezone">
        <xsl:choose>
            <xsl:when test="$dateTime gt xs:dateTime('2030-10-06T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2030-04-07T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2029-10-07T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2029-04-01T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2028-10-01T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2028-04-02T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2027-10-03T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2027-04-04T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2026-10-04T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2026-04-05T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2025-10-05T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2025-04-06T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2024-10-06T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2024-04-07T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2023-10-01T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2023-04-02T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2022-10-02T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2022-04-03T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2021-10-03T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2021-04-04T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2020-10-04T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2020-04-05T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2019-10-06T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2019-04-07T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2018-10-07T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2018-04-01T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2017-10-01T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2017-04-02T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2016-10-02T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2016-04-03T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2015-10-04T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2015-04-05T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2014-10-05T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2014-04-06T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2013-10-06T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2013-04-07T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2012-10-07T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2012-04-01T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2011-10-02T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2011-04-03T03:00:00+10:00')">PT10H</xsl:when>
            <xsl:when test="$dateTime gt xs:dateTime('2010-10-03T02:00:00+11:00')">PT11H</xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat(' Error - dateTime : ', $dateTime, ' out of range. Need to extend the list of DST datetimes.')"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="xs:dayTimeDuration($timezone)"/>
</xsl:function>

このコードにより、「TransformerConfigurationException:スタイルシートのコンパイルに失敗しました。1つのエラーが検出されました。」というエラーが発生します。

これが私が変換したい出力です:

<?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Body>
    <getDocumentByKeyResponse xmlns="http://www.abc.com/ws/integration/toolkit/2005/07" xmlns:ns1="http://www.abc.com/ws/integration/toolkit/2005/07" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <Document>
            <Attributes>
                <Attribute name="duration">0:00:00.086</Attribute>
                <Attribute name="count">2</Attribute>
                <Attribute name="entity">SourcingRequest</Attribute>
                <Attribute name="mode">XML</Attribute>
                <Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
            </Attributes>
            <Content>
                <ExportXML>
                    <record>
                        <field name="Identifier">00000abc</field>
                        <field name="ContestNumber">00000abc</field>
                        <field name="CareerSiteNo3">xyz</field>
                        <field name="OpeningDate">2012-02-15</field>
                        <field name="EndDate">2012-02-1602:00:00T-05:00</field>
                    </record>
            </Content>
        </Document>
    </getDocumentByKeyResponse>
</Body>

<xsl:value-of select="format-dateTime((xs:datetime($AUTime) + xs:dayTimeDuration($Duration)), $date-format)"/>このよう<xsl:value-of select="format-dateTime($AUTime, $date-format)"/>にデータ計算を含まない部分を変更する と、変換処理は成功します。

内部で計算することはできませんformat-dateTime()>か?

どうもありがとう

4

1 に答える 1

0

関数に引数を提供するために計算を行うこと可能ですが、xpath の「+」演算子は期待どおりに日時に対して機能しません。

http://www.w3.org/TR/2004/WD-xpath-functions-20041029/#dateTime-arithmeticをご覧ください。

于 2012-05-31T21:51:17.240 に答える