<mL>
<s>1</s>
<dt>2022-01-01-01.00.00</dt>
<q>10</q>
</mL>
<mL>
<s>2</s>
<dt>2022-01-01-02.00.00</dt>
<q>11</q>
</mL>
<mL>
<s>3</s>
<dt>2022-01-02-01.00.00</dt>
<q>12</q>
</mL>
<mL>
<s>4</s>
<dt>2022-01-02-02.00.00</dt>
<q>13</q>
</mL>
我必须根据变化的日期和时间间隔将这个结构转换成这样的东西,例如,在前2组ml
标签中,我们可以观察到<s>1</s>
和<s>2</s>
在这里有<dt>2022-01-02-01.00.00</dt>
和<dt>2022-01-02-02.00.00</dt>
"2022-01-02"日期和"01.00.00";,"02.00.00"是时间间隔,我们必须根据这些间隔创建元素的个数,只检查下面的示例。
<Interval>
<IntervalEnding_01.00.00>10</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>11</IntervalEnding_02.00.00>
</Interval>
<Interval>
<IntervalEnding_01.00.00>12</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>13</IntervalEnding_02.00.00>
</Interval>
我尝试使用模板
<xsl:template name="SplitInterval">
<!--xsl:element name="Report_Period_date"-->
<xsl:for-each select="ns1:idGrp/ns1:mL">
<xsl:element name="{concat('IntervalEnding','_', substring (ns1:dt, 1, 4 ),substring (ns1:dt, 6, 2 ),substring (ns1:dt, 9, 2 ),'_',substring (ns1:dt, 12, 2 ),substring (ns1:dt, 15, 2 ))}">
<xsl:value-of select="ns1:q"/>
</xsl:element>
</xsl:for-each>
<!--/xsl:element-->
</xsl:template>
但是我只能打印不带根间隔标签的
<IntervalEnding_01.00.00>12</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>13</IntervalEnding_02.00.00>
但是我需要在
下面打印<Interval>
<IntervalEnding_01.00.00>12</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>13</IntervalEnding_02.00.00>
</Interval>
我猜(!)你正试图做这样的事情:
XML(格式良好的! !)
<root>
<mL>
<s>1</s>
<dt>2022-01-01-01.00.00</dt>
<q>10</q>
</mL>
<mL>
<s>2</s>
<dt>2022-01-01-02.00.00</dt>
<q>11</q>
</mL>
<mL>
<s>3</s>
<dt>2022-01-02-01.00.00</dt>
<q>12</q>
</mL>
<mL>
<s>4</s>
<dt>2022-01-02-02.00.00</dt>
<q>13</q>
</mL>
</root>
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:template match="/root">
<output>
<xsl:for-each select="mL[position() mod 2 = 1]">
<Interval>
<xsl:for-each select=". | following-sibling::mL[1]">
<xsl:element name="IntervalEnding_{substring(dt, 12)}">
<xsl:value-of select="q"/>
</xsl:element>
</xsl:for-each>
</Interval>
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>
结果
<?xml version="1.0" encoding="UTF-8"?>
<output>
<Interval>
<IntervalEnding_01.00.00>10</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>11</IntervalEnding_02.00.00>
</Interval>
<Interval>
<IntervalEnding_01.00.00>12</IntervalEnding_01.00.00>
<IntervalEnding_02.00.00>13</IntervalEnding_02.00.00>
</Interval>
</output>