使用xslt将XML转换为txt

时间:2016-09-05 11:00:28

标签: xml xslt transform

<FlightPlan xmlns="http://aeec.aviation-ia.net/633" xmlns:extd="http://www.w3.org/2001/A633AIRBUSExtensions" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" category="normal" computedTime="2016-04-27T22:56:26" flightPlanId="OFP1" xsi:schemaLocation="http://aeec.aviation-ia.net/633 FlightPlan.xsd">
<M633Header timestamp="2016-04-27T22:57:05Z" versionNumber="2"/>
<M633SupplementaryHeader>
    <Flight flightOriginDate="2016-04-28" scheduledTimeOfDeparture="2016-04-28T04:55:00Z">
        <FlightIdentification>
            <FlightIdentifier>EZY8751</FlightIdentifier>
            <FlightNumber airlineIATACode="U2" number="8751">
                <CommercialFlightNumber>U28751</CommercialFlightNumber>
            </FlightNumber>
        </FlightIdentification>
        <DepartureAirport airportFunction="DepartureAirport" airportName="LONDON/GATWICK">
            <AirportICAOCode>EGKK</AirportICAOCode>
            <AirportIATACode>LGW</AirportIATACode>
        </DepartureAirport>
        <ArrivalAirport airportFunction="ArrivalAirport" airportName="KERKIRA/IOANNIS KAPODISTRIAS">
            <AirportICAOCode>LGKR</AirportICAOCode>
            <AirportIATACode>CFU</AirportIATACode>
        </ArrivalAirport>
    </Flight>
    <Aircraft aircraftRegistration="GEZWY">
        <AircraftModel airlineSpecificSubType="A320-CFM56-5B4/3-TI(SH) - MSN6267">
            <AircraftICAOType>A320</AircraftICAOType>
        </AircraftModel>
    </Aircraft>
</M633SupplementaryHeader>

我有以下xml。输出应如下所示:

  

FlightIdentifier | FlightOriginDate | AircraftRegistration
  EZY8751 | 20160428 | GEZWY

我试过这种方式,但它没有生成任何输出

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="text"/>

<xsl:template match="/">
    <xsl:apply-templates select="/FlightPlan/M633SupplementaryHeader/FlightIdentifier"/>


</xsl:template>
<!-- replace xsi:schemaLocation attribute -->
<xsl:template match="@xsi:schemaLocation">
    <xsl:attribute name="xsi:schemaLocation"></xsl:attribute>
</xsl:template>

1 个答案:

答案 0 :(得分:1)

您可以使用此XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aeec="http://aeec.aviation-ia.net/633"
exclude-result-prefixes="aeec">
  <xsl:output method="text"/>

  <xsl:template match="/">
    FlightIdentifier: <xsl:value-of select="aeec:FlightPlan/aeec:M633SupplementaryHeader/aeec:Flight/aeec:FlightIdentification/aeec:FlightIdentifier"/>
    FlightOriginDate: <xsl:value-of select="aeec:FlightPlan/aeec:M633SupplementaryHeader/aeec:Flight/@flightOriginDate"/>
    AircraftRegistration: <xsl:value-of select="aeec:FlightPlan/aeec:M633SupplementaryHeader/aeec:Aircraft/@aircraftRegistration"/>
  </xsl:template>

</xsl:stylesheet>

在线输出:http://xsltransform.net/6rewNxL