2011-06-28 14 views
0

XSLTを使用して、次のXMLを区切り記号「|」でフラットファイルに変換する必要があります。XSLTを使用したXMLからフラットファイルへの変換

これは私のXMLです:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?><GeneralLedgerReport targetNamespace="http://www.portal.com/schemas/GLSync" xmlns="http://www.portal.com/schemas/GLSync" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.portal.com/schemas/GLSync brm_gl_data.xsd"> 
     <SourceSystemID>Germany</SourceSystemID> 
     <ReportID>0.0.0.1-697031-1136</ReportID> 
     <RevenueType>Unbilled earned</RevenueType> 
     <BRM_GL_Segment>.</BRM_GL_Segment> 
     <ReportCreatedTime> 
       <Year>2013</Year> 
       <Month>01</Month> 
       <Day>14</Day> 
       <Hours>16</Hours> 
       <Minutes>2</Minutes> 
       <Seconds>3</Seconds> 
     </ReportCreatedTime> 
     <PeriodStartTime> 
       <Year>2012</Year> 
       <Month>10</Month> 
       <Day>15</Day> 
       <Hours>0</Hours> 
       <Minutes>0</Minutes> 
       <Seconds>0</Seconds> 
     </PeriodStartTime> 
     <PeriodEndTime> 
       <Year>2012</Year> 
       <Month>10</Month> 
       <Day>16</Day> 
       <Hours>0</Hours> 
       <Minutes>0</Minutes> 
       <Seconds>0</Seconds> 
     </PeriodEndTime> 
</GeneralLedgerReport> 

必要な出力: 総勘定元帳レポート

ドイツ| 0.0.0.1-697031-1136 |獲得した未請求| 2013/01/14-16:02: 03 | 2012/10/15-00:00:00 ドイツ| 0.0.0.1-697031-1136 |未請求獲得| 2013/01/14-16:02:03 | 2012/10/15-00:00:00 ドイツ| 0.0.0.1-697031-1136 |未請求獲得| 2013/01/14-16:02:03 | 2012/10/15-00:00:00 ドイツ| 0.0.0.1-697031-1136 |未請求獲得| 2013/01/14-16:02:03 | 2012/10/15-00:00:00

私は物事のカップルを試みたが、出力はとして提供されます:

が緊急にこれを必要とearned20130114160203201210150

をGermany0.0.0.1-697031-1136Unbilled、助けてください! ありがとう!

は、私は新しいXSLTに、区切り文字で別々の要素を取得する方法がわからない、私はこれを試してみました午前:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" 
     xmlns:java="http://xml.apache.org/xalan/java" exclude-result-prefixes="exslt java"> 
<xsl:output method="text" version="1.0" encoding="ISO-8859-1" indent="yes"/> 

     <xsl:template match="/"> 
      <xsl:apply-templates select="/"/> 
     </xsl:template> 
     <xsl:template match="/"> 
      <xsl:value-of select="."/> 
     </xsl:template> 

</xsl:stylesheet> 

詳細XML:

<SourceSystemID>Germany</SourceSystemID> 
    <ReportID>0.0.0.1-697031-1116</ReportID> 
    <RevenueType>Unbilled earned</RevenueType> 
    <BRM_GL_Segment>.</BRM_GL_Segment> 
    <ReportCreatedTime> 
      <Year>2013</Year> 
      <Month>01</Month> 
      <Day>14</Day> 
      <Hours>16</Hours> 
      <Minutes>1</Minutes> 
      <Seconds>59</Seconds> 
    </ReportCreatedTime> 
    <PeriodStartTime> 
      <Year>2012</Year> 
      <Month>09</Month> 
      <Day>25</Day> 
      <Hours>0</Hours> 
      <Minutes>0</Minutes> 
      <Seconds>0</Seconds> 
    </PeriodStartTime> 
    <PeriodEndTime> 
      <Year>2012</Year> 
      <Month>09</Month> 
      <Day>26</Day> 
      <Hours>0</Hours> 
      <Minutes>0</Minutes> 
      <Seconds>0</Seconds> 
    </PeriodEndTime> 
    <SourceSystemID>Germany</SourceSystemID> 
    <ReportID>0.0.0.1-697031-1136</ReportID> 
    <RevenueType>Unbilled earned</RevenueType> 
    <BRM_GL_Segment>.</BRM_GL_Segment> 
    <ReportCreatedTime> 
      <Year>2013</Year> 
      <Month>01</Month> 
      <Day>14</Day> 
      <Hours>16</Hours> 
      <Minutes>2</Minutes> 
      <Seconds>3</Seconds> 
    </ReportCreatedTime> 
    <PeriodStartTime> 
      <Year>2012</Year> 
      <Month>10</Month> 
      <Day>15</Day> 
      <Hours>0</Hours> 
      <Minutes>0</Minutes> 
      <Seconds>0</Seconds> 
    </PeriodStartTime> 
    <PeriodEndTime> 
      <Year>2012</Year> 
      <Month>10</Month> 
      <Day>16</Day> 
      <Hours>0</Hours> 
      <Minutes>0</Minutes> 
      <Seconds>0</Seconds> 
    </PeriodEndTime> 
+0

名前空間(接頭辞とURI)を宣言する必要がある場合は、入力ツリーの要素を選択できません。さらに、あなたが望む出力は正しいですか?それは4回繰り返された単なる行ですか? –

+0

@empo:基本的に入力は同じ方法で繰り返される巨大なXMLです。そのため、同じ数の行を繰り返す必要があります。接頭辞とURIを追加しようとします。これは正しいです? <?xmlのバージョンは、= "1.0" エンコード= "UTF-8"?> ます。 ます。 Gagan

+0

入力XMLのもう少しを投稿してください(コメントは使用しないでくださいあなたの質問を編集) –

答えて

1

はこの質問を見ているが、使用してみてください|代わりにコンマ

XSLT Concatenating the values with comma (,)

+0

Thanks Conrad!私はXSLTが新しく、各要素を別々に選ぶ方法がわからない。私は次のように試しました:<?xml version = "1.0" encoding = "UTF-8"?> xsl:template match = "/">これで助けてもらえますか? – Gagan

+0

イグナシオ、上記の記事をご覧ください。コードを投稿しました – Gagan

+0

私はそれを読んでいません。あなたの質問を編集してください。 –

0

の次のXSLTからいくつかのインスピレーションを得ることができます:

<?xml version='1.0' encoding='utf-8'?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:glsync="http://www.portal.com/schemas/GLSync" version="1.0"> 

    <xsl:output method="text" /> 

    <xsl:template match="glsync:GeneralLedgerReport"> 
     <xsl:value-of select="./glsync:SourceSystemID" /> 
     <xsl:text>|</xsl:text> 
     <xsl:value-of select="./glsync:ReportID" /> 
     <xsl:text>|</xsl:text> 
     <xsl:value-of select="./glsync:RevenueType" /> 
     <xsl:text>|</xsl:text> 
     <xsl:apply-templates select="./glsync:ReportCreatedTime" /> 
     <xsl:text>|</xsl:text> 
     <xsl:apply-templates select="./glsync:PeriodStartTime" /> 
    </xsl:template> 

    <xsl:template match="glsync:ReportCreatedTime"> 
     <xsl:value-of 
      select="concat(
       glsync:Year, '/', 
       glsync:Month, '/', 
       glsync:Day, '-', 
       format-number(glsync:Hours, '00'), ':', 
       format-number(glsync:Minutes, '00'), ':', 
       format-number(glsync:Seconds, '00'))" /> 
    </xsl:template> 

    <xsl:template match="glsync:PeriodStartTime"> 
     <xsl:value-of 
      select="concat(
       glsync:Year, '/', 
       glsync:Month, '/', 
       glsync:Day, '-', 
       format-number(glsync:Hours, '00'), ':', 
       format-number(glsync:Minutes, '00'), ':', 
       format-number(glsync:Seconds, '00'))" /> 
    </xsl:template> 

</xsl:stylesheet> 

いくつかの注意を:

  • ので、あなたのあなたは、要素にマッチする名前空間を使用する必要があります。 XMLはtargetNamespaceです。

  • あなたはglsync:GeneralLedgerReport

  • ノート時間を取得するためのformat-number機能の使用、2桁ついに

  • の分と秒をテンプレートマッチングにもconcat機能を使用することができ、あなたの長いXMLは思わすべてがGeneralLedgerReportReportCreatedTimePeriodStartTimeおよびPeriodEndTimeのタグは同じレベルにあるので、奇妙なものです。おそらくあなたは、あなたが私はこれが役に立てば幸いすべてのGeneralLedgerReport

ための構造を入れ子にしているように、それらを囲むいくつかのタグを持っています。

関連する問題