タイムスタンプと理由コードごとに人口を合計したいと思います。以下のサンプルコードを考えると、機能していませんでした。plsはそれを機能させるのを手伝ってくれませんか
私のXML:
次のXMLを入力ファイルとして使用しました
<?xml version="1.0" encoding="UTF-8"?>
<Earnings>
<Collection>
<Timestamp>20170101</Timestamp>
<Points>100</Points>
<ReasonCode>AN</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170102</Timestamp>
<Points>100</Points>
<ReasonCode>AN</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170101</Timestamp>
<Points>10000</Points>
<ReasonCode>BP</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170101</Timestamp>
<Points>10000</Points>
<ReasonCode>BP</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170102</Timestamp>
<Points>100</Points>
<ReasonCode>PPTS</ReasonCode>
</Collection>
</Earnings>
私のXSLT
XMLを指定された形式に変換するために使用される次のXSLTを使用しました
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:key name="Earnings" match="Earnings/Collection" use="concat(Timestamp, '+',ReasonCode)"/>
<xsl:template match="Earnings">
<Earnings>
<xsl:for-each select="Collection[generate-id() = generate-id(key('Earnings', concat(Timestamp, '+',ReasonCode))[1])]">
<xsl:sort select="concat(Timestamp, '+',ReasonCode)"/>
<xsl:variable name="current-group" select="/Earnings/Collection[ReasonCode = current()/ReasonCode]"/>
<Collection>
<Timestamp>
<xsl:value-of select="Timestamp"/>
</Timestamp>
<Points>
<xsl:value-of select="sum($current-group/Points)"/>
</Points>
<ReasonCode>
<xsl:value-of select="ReasonCode"/>
</ReasonCode>
</Collection>
</xsl:for-each>
</Earnings>
</xsl:template>
</xsl:stylesheet>
期待される出力
<Collection>
<Timestamp>20170101</Timestamp>
<Points>100</Points>
<ReasonCode>AN</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170101</Timestamp>
<Points>2000</Points>
<ReasonCode>BP</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170102</Timestamp>
<Points>100</Points>
<ReasonCode>AN</ReasonCode>
</Collection>
<Collection>
<Timestamp>20170102</Timestamp>
<Points>100</Points>
<ReasonCode>PPTS</ReasonCode>
</Collection>
ありがとう、
モハン
変化する:
<xsl:variable name="current-group" select="/Earnings/Collection[ReasonCode = current()/ReasonCode]"/>
に:
<xsl:variable name="current-group" select="key('Earnings', concat(Timestamp, '+',ReasonCode))"/>
あなたが今持っているものは、それらに関係なく、現在のものCollection
と同じReasonCode
ものですべてのを合計Collection
しTimestamp
ます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加