XML文書をCSVに変換して変換するXSLTがあります。しかし、読みにくく(私はすべての "../../"参照が嫌いです)、それらがパフォーマンスを傷つけるかどうか、私が変換しているファイルは大きいと思います。私はいくつかの異なる例を見てきましたが、私は下のものだけを動作させることができました。XML文書をCSVフラットファイルに変換するための、より効率的なXSLT
私の質問は次のとおりです。 1.このXSLTをより簡潔にし、 "../ .."参照を使用しないように書き換えることができますか? 2. "../ .."型参照は、何らかの形で値を格納するよりも効率が悪いです。
以下のサンプル。 おかげで、 ジョン
相続人XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="Document"/>
</xsl:template>
<xsl:template match="Document">
<xsl:apply-templates select="DocBody"/>
</xsl:template>
<xsl:template match="DocBody">
<xsl:apply-templates select="Values"/>
</xsl:template>
<xsl:template match="Values">
<xsl:apply-templates select="IntervalValues"/>
</xsl:template>
<xsl:template match="IntervalValues">
<xsl:apply-templates select="Quantity"/>
</xsl:template>
<xsl:template match="Quantity">
<xsl:value-of select="concat(../../../../DocHeader/DocTitle,',',../../../../DocHeader/CreatedAt,',',../../../DeliveryDate,',',../../../DeliveryHour,',',../Interval,',',Type,',',Value)"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
HERESに小さなXMLサンプル:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<DocHeader>
<DocTitle>Totals Report</DocTitle>
<DocRevision>1</DocRevision>
<CreatedAt>2011-02-10T21:25:00</CreatedAt>
</DocHeader>
<DocBody>
<DeliveryDate>2011-02-10</DeliveryDate>
<DeliveryHour>22</DeliveryHour>
<Values>
<IntervalValues>
<Interval>1</Interval>
<Quantity>
<Type>Energy</Type>
<Value>18053.5</Value>
</Quantity>
<Quantity>
<Type>Loss</Type>
<Value>438.7</Value>
</Quantity>
<Quantity>
<Type>Load</Type>
<Value>17614.8</Value>
</Quantity>
</IntervalValues>
<IntervalValues>
<Interval>2</Interval>
<Quantity>
<Type>Energy</Type>
<Value>17940.7</Value>
</Quantity>
<Quantity>
<Type>Loss</Type>
<Value>437.7</Value>
</Quantity>
<Quantity>
<Type>Load</Type>
<Value>17503</Value>
</Quantity>
</IntervalValues>
<IntervalValues>
<Interval>3</Interval>
<Quantity>
<Type>Energy</Type>
<Value>17871.7</Value>
</Quantity>
<Quantity>
<Type>Loss</Type>
<Value>437.4</Value>
</Quantity>
<Quantity>
<Type>Load</Type>
<Value>17434.3</Value>
</Quantity>
</IntervalValues>
</Values>
</DocBody>
</Document>
HERESにサンプル出力
Totals Report,2011-02-10T21:25:00,2011-02-10,22,1,Energy,18053.5
Totals Report,2011-02-10T21:25:00,2011-02-10,22,1,Loss,438.7
Totals Report,2011-02-10T21:25:00,2011-02-10,22,1,Load,17614.8
Totals Report,2011-02-10T21:25:00,2011-02-10,22,2,Energy,17940.7
Totals Report,2011-02-10T21:25:00,2011-02-10,22,2,Loss,437.7
Totals Report,2011-02-10T21:25:00,2011-02-10,22,2,Load,17503
Totals Report,2011-02-10T21:25:00,2011-02-10,22,3,Energy,17871.7
Totals Report,2011-02-10T21:25:00,2011-02-10,22,3,Loss,437.4
Totals Report,2011-02-10T21:25:00,2011-02-10,22,3,Load,17434.3
ありがとうございました。私はこれらの答えに感謝します。 – John