简体   繁体   中英

XSLT newbie - XML import into MS Access leaves element values blank

I have been writing an (incredibly simple) XSLT to get MS Access to read this XML document that I get from another software package, and I am having trouble getting the values of the elements to transfer over. When I source the XML document and apply the XSLT transformation, it gives me 5 fields, "EventID", "DeviceID", "Officer", "Start", and "Stop", which is great. The EventID, Start, and Stop fields all source attributes from the XML document successfully, but the DeviceID and Officer elements come up blank.

Here's the source 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>

Here's the XSLT that I am using:

<?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>

That's it. I tried searching the question database on here, and I think it has something to do with namespaces maybe, but no luck when I messed with them.

导入MS Access时的外观

I would like it to return:

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

What it's currently giving me:

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

Your paths are off for matching elements within the XML. Office and Vehicle are both nested elements of the Info element. Try using the following XSL and you should get values for Vehicle (DeviceID) and Officer as well:

<?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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM