<BatchInput>
<DealInfoObject>
<DealThirdParty>
<ThirdpartyPayment>
<DueDate></DueDate>
<DeliveryDate>28/02/2018 12:00:00 AM</DeliveryDate>
<AdvanceDate>01/01/0001 12:00:00 AM</AdvanceDate>
<ThirdPartySchedule>
<DueDate>29/01/2018 12:00:00 AM</DueDate>
</ThirdPartySchedule>
</ThirdpartyPayment>
<DealThirdParty>
<DealInfoObject>
<BatchInput>
我的一些xml文件,我想在文件上循环并使用xslt更改所有日期获取所有日期,如此格式2018-04-15T00:00:00
答案 0 :(得分:0)
该示例关于输入格式不明确。假设小时数为零填充到2位数,您可以执行以下操作:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="DeliveryDate | AdvanceDate | DueDate">
<xsl:copy>
<xsl:variable name="d" select="substring(., 1, 2)"/>
<xsl:variable name="m" select="substring(., 4, 2)"/>
<xsl:variable name="y" select="substring(., 7, 4)"/>
<xsl:variable name="h12" select="substring(., 12, 2)"/>
<xsl:variable name="mmss" select="substring(., 14, 6)"/>
<xsl:variable name="pm" select="contains(.,'P')"/>
<xsl:variable name="h24" select="$h12 mod 12 + 12*$pm"/>
<xsl:value-of select="$y"/>
<xsl:value-of select="format-number($m, '-00')"/>
<xsl:value-of select="format-number($d, '-00')"/>
<xsl:value-of select="format-number($h24, 'T00')"/>
<xsl:value-of select="$mmss"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
如果你真的有空的日期元素,这需要更多的工作。
答案 1 :(得分:-1)
由于您没有指定XSLT版本,我使用的是2.0版。
我的想法是转换包含日期的每个文本节点 格式为“正确”格式。 如果文本节点具有其他内容(与日期模式不匹配) 它保持不变。
优点是,如果你有其他带日期的标签, 没有必要更改XSLT脚本。
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
<xsl:template match="text()[normalize-space()]">
<xsl:variable name="mtch"
select="matches(., '^\d\d/\d\d/\d{4} \d\d:\d\d:\d\d [A|P]M$')"/>
<xsl:if test="$mtch">
<xsl:variable name="dt" select="xs:date(concat(
substring(., 7, 4), '-', substring(., 4, 2), '-', substring(., 1, 2)))"/>
<xsl:variable name="am" as="xs:string" select="substring(., 21, 2)"/>
<xsl:variable name="hr" as="xs:string" select="substring(., 12, 2)"/>
<xsl:variable name="hri" as="xs:integer" select="
if ($am = 'AM') then xs:integer($hr) mod 12
else xs:integer($hr) mod 12 + 12"/>
<xsl:variable name="hrs" as="xs:string" select="format-number($hri, '00')"/>
<xsl:variable name="mm" as="xs:string" select="substring(., 15, 2)"/>
<xsl:variable name="ss" as="xs:string" select="substring(., 18, 2)"/>
<xsl:variable name="tm" select="xs:time(concat($hrs, ':', $mm, ':', $ss))"/>
<xsl:variable name="dtm" select="dateTime($dt, $tm)"/>
<xsl:value-of select="$dtm"/>
</xsl:if>
<xsl:if test="not($mtch)">
<xsl:value-of select="."/>
</xsl:if>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
</xsl:transform>
答案 2 :(得分:-2)
使用xml linq:
} into g
select new
{
Kunde_Kz = g.Key.Kunde_Kz,
Geschäftspartner = g.Key.Geschäftspartner,
Art_Gruppe = g.Key.Art_Gruppe,
//Auftragsposition = g.Key.Auftragsposition,
Deckungsbeitrag = g.Sum(x => x.Field<double>("Deckungsbeitrag")),
Erlös = g.Sum(x => x.Field<double>("Erlös")),
Dienst = g.Sum(x => x.Field<double>("Dienst")),
IS_Erlös = g.Sum(x => x.Field<double>("IS_Erlös")),
Ware_in = g.Sum(x => x.Field<double>("Ware_in")),
Ware_out = g.Sum(x => x.Field<double>("Ware_out")),
Mieten = g.Sum(x => x.Field<double>("Mieten")),
Kosten = g.Sum(x => x.Field<double>("Kosten")),
Dienst_kosten = g.Sum(x => x.Field<double>("Dienst_kosten")),
Verarbeitung = g.Sum(x => x.Field<double>("Verarbeitung")),
Ware_in_kosten = g.Sum(x => x.Field<double>("Ware_in_kosten")),
Ware_out_kosten = g.Sum(x => x.Field<double>("Ware_out_kosten")),
Mieten_kosten = g.Sum(x => x.Field<double>("Mieten_kosten"))
}).ToList();