XSLT:文档末尾的额外内容

时间:2016-08-12 10:45:25

标签: xml xslt copy

我收到以下XSLT代码的错误。

我正在尝试从源代码复制元素。

当排除部分代码时,它可以正常工作。

  <xsl:copy>
      <Header>
        <xsl:copy-of select="xp:Header/*"/>
      </Header>
    </xsl:copy>

但是当我在上面的代码中包含它时,它给了我错误。

以下是完整代码

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xp="http://www.reverseXSL.com/FreeParser">

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="/*">

  <xsl:copy>
      <Header>
        <xsl:copy-of select="xp:Header/*"/>
      </Header>
    </xsl:copy>

     <xsl:copy>
      <ObservationStationDetails>
        <xsl:copy-of select="xp:ObservationStationDetails/*"/>
      </ObservationStationDetails>
    </xsl:copy>
  </xsl:template>

    </xsl:stylesheet>

请建议。

这里是输入xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="FinalXSLT.xsl"?>
<Sample_1 xmlns="http://www.reverseXSL.com/FreeParser" messageID="160811_183146">
   <Header>
      <Dept>            INDIA METEOROLOGICAL DEPARTMENT</Dept>
   </Header>
   <SubHeader>
      <Computation>             RS/RW COMPUTATION</Computation>
   </SubHeader>
   <line1>
      <blankline>   _______________________________________________________________________</blankline>
   </line1>
   <Header1>
      <Tag1>    [FLIGHT START TIME]</Tag1>
   </Header1>
   <FlightStartTime>
      <BRT> Balloon Release Time        = 08 Apr 2016 06:22:39</BRT>
   </FlightStartTime>
   <Header2>
      <Tag2>    [OBSERVATION STATION DETAILS ]</Tag2>
   </Header2>
   <ObservationStationDetails>
      <StName>  Station Name            = CHIKA</StName>
   </ObservationStationDetails>
   <ObservationStationDetails>
      <StHt>    Station Ht.         = 500 m</StHt>
   </ObservationStationDetails>
   <ObservationStationDetails>
      <StIndex> Station Index           = 43000</StIndex>
   </ObservationStationDetails>
   <ObservationStationDetails>
      <Latitude>    Latitude            = 69.51 N</Latitude>
   </ObservationStationDetails>
   <ObservationStationDetails>
      <Longitude>   Longitude           = 75.24 E</Longitude>
   </ObservationStationDetails>
   <ObservationStationDetails>
      <Zonal>   Zonal No.           = xxxx</Zonal>
   </ObservationStationDetails>
  </Sample_1>

必填项:

<Sample_1 xmlns="http://www.reverseXSL.com/FreeParser">
<Header xmlns:xp="http://www.reverseXSL.com/FreeParser">
<Header>
<Dept>INDIA METEOROLOGICAL DEPARTMENT</Dept>
</Header>
</Header>
<ObservationStationDetails xmlns:xp="http://www.reverseXSL.com/FreeParser">
<StName>Station Name    = CHIKA</StName>
<StHt>Station Ht.   = 500 m</StHt>
<StIndex>Station Index  = 43000</StIndex>
<Latitude>Latitude  = 69.51 N</Latitude>
<Longitude>Longitude    = 75.24 E</Longitude>
<Zonal>Zonal No.    = xxxx</Zonal>
</ObservationStationDetails>
</Sample_1>

1 个答案:

答案 0 :(得分:0)

它对我有用

 <xsl:copy>
  <Header>
    <xsl:copy-of select="xp:Header"/>
  </Header>
  <ObservationStationDetails>
    <xsl:copy-of select="xp:ObservationStationDetails/*"/>
  </ObservationStationDetails>
</xsl:copy>