【问题标题】:XSLT newbie - XML import into MS Access leaves element values blankXSLT 新手 - 将 XML 导入 MS Access 将元素值留空
【发布时间】:2016-12-29 16:22:44
【问题描述】:

我一直在编写一个(非常简单的)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>

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

我希望它返回:

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

【问题讨论】:

  • 您必须在 XML 中向我们展示预期的输出和所需的输出。

标签: xml ms-access xslt element value-of


【解决方案1】:

您的路径无法匹配 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> 

【讨论】:

  • 非常感谢!感谢您的宝贵时间!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-13
  • 1970-01-01
相关资源
最近更新 更多