我需要使用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 | Unbilled賺取| 2013/01/14-16:02:03 | 2012/10/15-00:00:00 德國| 0.0.0.1-697031-1136 | Unbilled賺得| 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
我試過幾件事情,但輸出當屬:
Germany0.0.0.1-697031-1136Unbilled earned20130114160203201210150
需要此緊急,請大家幫助! 謝謝!
我是新來的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>
您必須聲明命名空間(前綴和URI),否則您將無法在輸入樹中選擇元素。而且,你想要的輸出是否正確?這只是一個重複四次? –
@empo:基本上輸入是一個巨大的XML以相同的方式重複,這就是爲什麼我需要輸出爲相同數量的行重複。我會嘗試添加前綴和URI。它是否正確? <?xml version =「1.0」encoding =「UTF-8」?> –
Gagan
請發佈多一點您的輸入xml(編輯您的問題請勿使用評論) –