为MS Access导入创建XML转换文件

时间:2017-09-07 15:24:46

标签: xml ms-access xslt

我需要帮助为以下XML代码创建XSLT转换文件。 最后,访问中导入的数据应该包含以下列: "消息UID","时间"," IRCPTACTION"," TRACKERID"," ORCPTS","交付","接受"," TLS_RECEIVED"," SENDER"," SOURCE"," SUBJECT"。 ..等等。

我尝试根据本网站上的一些示例创建我的XSLT文件,但由于我在使用XML方面处于领先状态,因此我没有达到目标。

有人可以帮我构建XSLT文件的第一部分吗?

    <message UID="d4622233-f99ff70000003b12-f4-59b0dc8a55f9">
    <events>
        <event time="1504763018" name="IRCPTACTION">Test@test.com|deliver</event>
        <event time="1504763018" name="TRACKERID">Test@test.com|iiiiiddddddd</event>
        <event time="1504763018" name="ORCPTS">Test@test.com</event>
        <event time="1504763019" name="DELIVER">192.168.1.1:25|Test@test.com</event>
        <event time="1504763018" name="ACCEPT">192.168.1.2:33564</event>
        <event time="1504763018" name="TLS_RECEIVED">yes</event>
        <event time="1504763018" name="SENDER">Me</event>
        <event time="1504763018" name="SOURCE">external</event>
        <event time="1504763018" name="SUBJECT">Test Message</event>
        <event time="1504763018" name="MSGID">Message_ID;</event>
        <event time="1504763018" name="MSG_SIZE">2</event>
        <event time="1504763018" name="EHLO">MyServer</event>
        <event time="1504763018" name="LOGICAL_IP">192.168.1.1</event>
        <event time="1504763018" name="FIRED">Test@test.com|none</event>
        <event time="1504763018" name="VERDICT">Test@test.com|none|default</event>
        <event time="1504763018" name="UNTESTED">Test@test.com|has_urls|dz_document|</event>
    </events>
</message>
<message UID="d4622233-f81ff70000003b12-c8-59b0105f670f">
    <events>
                    <event time="1504763018" name="IRCPTACTION">Test@test.com|deliver</event>
        <event time="1504763018" name="TRACKERID">Test@test.com|iiiiiddddddd</event>
        <event time="1504763018" name="ORCPTS">Test@test.com</event>
        <event time="1504763019" name="DELIVER">192.168.1.1:25|Test@test.com</event>
        <event time="1504763018" name="ACCEPT">192.168.1.2:33564</event>
        <event time="1504763018" name="TLS_RECEIVED">yes</event>
        <event time="1504763018" name="SENDER">Me</event>
        <event time="1504763018" name="SOURCE">external</event>
        <event time="1504763018" name="SUBJECT">Test Message</event>
        <event time="1504763018" name="MSGID">Message_ID;</event>
        <event time="1504763018" name="MSG_SIZE">2</event>
        <event time="1504763018" name="EHLO">MyServer</event>
        <event time="1504763018" name="LOGICAL_IP">192.168.1.1</event>
        <event time="1504763018" name="FIRED">Test@test.com|none</event>
        <event time="1504763018" name="VERDICT">Test@test.com|none|default</event>
        <event time="1504763018" name="UNTESTED">Test@test.com|has_urls|dz_document|</event>
    </events>
</message>

1 个答案:

答案 0 :(得分:0)

只需将<message>属性映射到元素名称和保留文本,即可重新编写<event>@name个节点。 MESSAGE_UID TIMER 运行一次,因为它对所有孩子都是一样的。

XSLT (假设<messages>是没有xmlns命名空间的根)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/messages">  
        <xsl:copy> 
            <xsl:apply-templates select="message"/>
        </xsl:copy>
    </xsl:template>

    <!-- RE-WRITE MESSSAGE NODE -->
    <xsl:template match="message"> 
        <xsl:copy>  
            <MESSAGE_UID><xsl:value-of select="@UID"/></MESSAGE_UID>
            <TIMER><xsl:value-of select="events/event/@time"/></TIMER>
            <xsl:apply-templates select="events/event"/>
        </xsl:copy>       
    </xsl:template>

    <!-- MAP ATTRIBUTE TO NEW NODE NAMES, RETAINING EVENT TEXT -->
    <xsl:template match="events/event">
    <xsl:element name="{@name}">
            <xsl:value-of select="."/>
        </xsl:element>
    </xsl:template>

</xsl:stylesheet>

输出 (足够平以导入MS Access表格)

<?xml version="1.0"?>
<messages>
  <message>
    <MESSAGE_UID>d4622233-f99ff70000003b12-f4-59b0dc8a55f9</MESSAGE_UID>
    <TIMER>1504763018</TIMER>
    <IRCPTACTION>Test@test.com|deliver</IRCPTACTION>
    <TRACKERID>Test@test.com|iiiiiddddddd</TRACKERID>
    <ORCPTS>Test@test.com</ORCPTS>
    <DELIVER>192.168.1.1:25|Test@test.com</DELIVER>
    <ACCEPT>192.168.1.2:33564</ACCEPT>
    <TLS_RECEIVED>yes</TLS_RECEIVED>
    <SENDER>Me</SENDER>
    <SOURCE>external</SOURCE>
    <SUBJECT>Test Message</SUBJECT>
    <MSGID>Message_ID;</MSGID>
    <MSG_SIZE>2</MSG_SIZE>
    <EHLO>MyServer</EHLO>
    <LOGICAL_IP>192.168.1.1</LOGICAL_IP>
    <FIRED>Test@test.com|none</FIRED>
    <VERDICT>Test@test.com|none|default</VERDICT>
    <UNTESTED>Test@test.com|has_urls|dz_document|</UNTESTED>
  </message>
  <message>
    <MESSAGE_UID>d4622233-f81ff70000003b12-c8-59b0105f670f</MESSAGE_UID>
    <TIMER>1504763018</TIMER>
    <IRCPTACTION>Test@test.com|deliver</IRCPTACTION>
    <TRACKERID>Test@test.com|iiiiiddddddd</TRACKERID>
    <ORCPTS>Test@test.com</ORCPTS>
    <DELIVER>192.168.1.1:25|Test@test.com</DELIVER>
    <ACCEPT>192.168.1.2:33564</ACCEPT>
    <TLS_RECEIVED>yes</TLS_RECEIVED>
    <SENDER>Me</SENDER>
    <SOURCE>external</SOURCE>
    <SUBJECT>Test Message</SUBJECT>
    <MSGID>Message_ID;</MSGID>
    <MSG_SIZE>2</MSG_SIZE>
    <EHLO>MyServer</EHLO>
    <LOGICAL_IP>192.168.1.1</LOGICAL_IP>
    <FIRED>Test@test.com|none</FIRED>
    <VERDICT>Test@test.com|none|default</VERDICT>
    <UNTESTED>Test@test.com|has_urls|dz_document|</UNTESTED>
  </message>
</messages>