XML 문서를 CSV로 변환하고 변환하는 XSLT가 있습니다. 그러나 읽기가 힘들어 ("../../"참조가 모두 마음에 들지 않습니다.) 또한 성능이 손상되는지 궁금합니다. 변환하려는 파일이 큽니다. 몇 가지 다른 예를 살펴 보았지만 그 중 하나만 작동하도록 만들 수있었습니다.XML 문서를 CSV 플랫 파일로 변환하기위한보다 효율적인 XSLT
제 질문은 : 입니다. 1.이 XSLT를 "간략하게"및 "../ .."참조를 사용하지 않기 위해 다시 작성할 수 있습니까? 2. "../ .."형식 참조는 값을 저장하는 것보다 덜 효율적입니다.
아래의 샘플. 감사합니다, 존
을 heres 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