0

我一直在编写一个(非常简单的)XSLT 来让 MS Access 读取我从另一个软件包获得的这个 XML 文档,但我无法获取要传输的元素的值。当我获取 XML 文档并应用 XSLT 转换时,它给了我 5 个字段,“EventID”、“DeviceID”、“Officer”、“Start”和“Stop”,这很棒。EventID、Start 和 Stop 字段都成功地来自 XML 文档的源属性,但 DeviceID 和 Officer 元素出现空白。

这是源 XML:

<?xml version="1.0" encoding="UTF-8"?>
<recording-event desiredStreamState="Routine" dvr="dvr" stop-time="2016-12-22T02:28:21Z" start-time="2016-12-22T02:20:08Z" stop-tick="1996428" start-tick="1995441" reid="00:00:12:a0:27:c0-1990499">
  <info>
    <officer id="60">Foo Bar</officer>
    <dept>9bcd1176-1c45-493f-ac27-440f1e191feb</dept>
    <vehicle>VHC2-010176</vehicle>
    <protected>0</protected>
  </info>
  <video hashType="none">
    <metadata hashCode="1b569a7dcb7f0212b574e303a4eb8031" name="tick1990499-tick1990499.mtd"/>
    <streams>
      <stream stop-tick="1996428" start-tick="1995441" num="1">
        <file hashCode="0e089f550866d3c8dd6d898516fdbb33" name="tick1995441-tick1996428-video1.mp4"/>
        <file hashCode="113fd040423905529e456985b160298b" name="tick1995441-tick1996428-video1.vtt"/>
        <file hashCode="c87cbb2e85292d3a8024cf7000473736" name="tick1995441-tick1996428-video1.json"/>
      </stream>
    </streams>
  </video>
  <etl ContentsRevision="1"/>
</recording-event>

这是我正在使用的 XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="recording-event">
    <Info>
      <EventID><xsl:apply-templates select="@reid"/></EventID>
      <DeviceID><xsl:value-of select="vehicle"/></DeviceID>
      <Officer><xsl:value-of select="officer"/></Officer>
      <Start><xsl:apply-templates select="@start-time"/></Start>
      <Stop><xsl:apply-templates select="@stop-time"/></Stop>
    </Info>
  </xsl:template>

</xsl:stylesheet>

而已。我尝试在这里搜索问题数据库,我认为它可能与命名空间有关,但是当我弄乱它们时没有运气。

导入 MS Access 时的样子

我希望它返回:

EventID= 2:a0:27:c0-1990499
DeviceID= VHC2-010176
Officer= Foo Bar
Start= 2016-12-22T02:28:21Z
Stop= 2016-12-22T02:28:21Z

它目前给我的东西:

EventID= 2:a0:27:c0-1990499
DeviceID=
Officer=
Start= 2016-12-22T02:28:21Z
Stop= 2016-12-22T02:28:21Z
4

1 回答 1

0

您的路径无法匹配 XML 中的元素。Office 和 Vehicle 都是 Info 元素的嵌套元素。尝试使用以下 XSL,您还应该获得 Vehicle (DeviceID) 和 Officer 的值:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="recording-event">
<Info>
  <EventID><xsl:apply-templates select="@reid"/></EventID>
  <DeviceID><xsl:value-of select="info/vehicle"/></DeviceID>
  <Officer><xsl:value-of select="info/officer"/></Officer>
  <Start><xsl:apply-templates select="@start-time"/></Start>
  <Stop><xsl:apply-templates select="@stop-time"/></Stop>
</Info>
</xsl:template> 

于 2016-12-29T16:44:36.117 回答