gpt4 book ai didi

xml - 如何构建与 xsltproc 一起使用的样式表以将 xml 转换为 csv

转载 作者:太空宇宙 更新时间:2023-11-04 05:46:59 25 4
gpt4 key购买 nike

需要使用 bash shell 将 xml 文件转换为 csv。检查我们在 Linux 主机上是否有可用的 xsltproc。如果还有其他方法可以通过 bash shell 将其转换为 csv。请告诉我。xml文件如下:

<?xml version="1.0' encoding="utf-8" standalone="yes"?>
<ns1:CommunicationHistoryResponse xmlns:nsl="http://www.itc.com/bd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ns1:NumPagesAvailable>10</ns1:NumPagesAvailable>
<ns1:Reason>
<ns1:ReasonCode>REQ_SUCCESS</ns1:ReasonCode>
<ns1:ReasonDescription>Fetch Communication History
Successful</ns1:ReasonDescription>
</ns1:Reason>
<ns1:CommunicationHistoryList>
<ns1:CommunicationHistory>
<ns1:lastModified>2019-03-18T00:00:10+00:00:00</ns1:lastModified>
<ns1:id>290805235</ns1:id>
<ns1:cLIName>null</ns1:cLIName>
<ns1:cLINumber>null</ns1:cLINumber>
<ns1:buttonNumber>1</ns1:buttonNumber>
<ns1:callType>resource</ns1:callType>
<ns1:callUsage>none</ns1:callUsage>
<ns1:destination>null</ns1:destination>
<ns1:deviceChannel>7</ns1:deviceChannel>
<ns1:deviceChannelType>Speaker</ns1:deviceChannelType>
<ns1:deviceIdId>268435490</ns1:deviceIdId>
<ns1:displayInCallHistory>true</ns1:displayInCallHistory>
<ns1:duration>27</ns1:duration>
<ns1:e164Destination xsi:nill="true" />
<ns1:eventType>Initiated</ns1:eventType>
<ns1:parentUserCDIId>369098755</ns1:parentUserCDIId>
<ns1:personalPointofContactId>0</ns1:personalPointofContactId>
<ns1:pointofContactId>0</ns1:pointofContactId>
<ns1:priority>none</ns1:priority>
<ns1:reasonForDisconnect xsi:nil="true" />
<ns1:resourceAORId>33563751</ns1:resourceAORId>
<ns1:rolloverAppearance>1</ns1:rolloverAppearance>
<ns1:routedDestination></ns1:routedDestination>
<ns1:schemaDifference_blob_reserved xsi:nil="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns1:schemaDifference_reserved>{}</ns1:schemaDifference_reserved>
<ns1:startTime>2019-03-17T23:59:43+00:00</ns1:startTime>
<ns1:trunkBchannel>-1</ns1:trunkBchannel>
<ns1:trunkId>335543181</ns1:trunkId>
<ns1:userId>33454412</ns1:userid>
</ns1:CommunicationHistory>
<ns1:CommunicationHistory>
<ns1:lastModified>2019-02-18T00:00:10+00:00:00</ns1:lastModified>
<ns1:id>290805245</ns1:id>
<ns1:cLIName>null</ns1:cLIName>
<ns1:cLINumber>null</ns1:cLINumber>
<ns1:buttonNumber>2</ns1:buttonNumber>
<ns1:callType>resource</ns1:callType>
<ns1:callUsage>none</ns1:callUsage>
<ns1:destination>null</ns1:destination>
<ns1:deviceChannel>7</ns1:deviceChannel>
<ns1:deviceChannelType>Speaker</ns1:deviceChannelType>
<ns1:deviceIdId>268436230</ns1:deviceIdId>
<ns1:displayInCallHistory>true</ns1:displayInCallHistory>
<ns1:duration>26</ns1:duration>
<ns1:e164Destination xsi:nill="true" />
<ns1:eventType>Initiated</ns1:eventType>
<ns1:parentUserCDIId>369198755</ns1:parentUserCDIId>
<ns1:personalPointofContactId>0</ns1:personalPointofContactId>
<ns1:pointofContactId>0</ns1:pointofContactId>
<ns1:priority>none</ns1:priority>
<ns1:reasonForDisconnect xsi:nil="true" />
<ns1:resourceAORId>33552751</ns1:resourceAORId>
<ns1:rolloverAppearance>1</ns1:rolloverAppearance>
<ns1:routedDestination></ns1:routedDestination>
<ns1:schemaDifference_blob_reserved xsi:nil="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<ns1:schemaDifference_reserved>{}</ns1:schemaDifference_reserved>
<ns1:startTime>2019-02-17T23:59:43+00:00</ns1:startTime>
<ns1:trunkBchannel>-1</ns1:trunkBchannel>
<ns1:trunkId>335543191</ns1:trunkId>
<ns1:userId>33454413</ns1:userid>
</ns1:CommunicationHistory>
</ns1:CommunicationHistoryList>
</nsl:CommunicationHistoryResponse>

我尝试构建 XSL 样式表,但没有成功。以下是我尝试过的样式表的详细信息。 root 位于 ns1:CommunicationHistoryResponse。ns1:NumPagesAvailable、ns1:ReasonCode、ns1:ReasonDescription 可以对每个基础记录重复。

 <?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/root"> ns1:lastModified;
ns1:id;ns1:cLIName;ns1:cLINumber;ns1:buttonNumber;ns1:callType;
ns1:callUsage;ns1:destination;ns1:deviceChannel;
ns1:deviceChannelTypeSpeaker;
ns1:deviceIdId;
ns1:displayInCallHistory;
ns1:duration;
ns1:e164Destination;
ns1:eventType;
ns1:parentUserCDIId;
ns1:personalPointofContactId;
ns1:pointofContactId;
ns1:priority;
ns1:reasonForDisconnect;
ns1:resourceAORId;
ns1:rolloverAppearance;
ns1:routedDestination;
ns1:schemaDifference_blob_reserved;
ns1:schemaDifference_reserved;
ns1:startTime;
ns1:trunkBchannel;
ns1:trunkId;
ns1:userId
<xsl:for-each select="record">
<xsl:for-each select="data"><xsl:value-of select="ns1:lastModified"/>;
<xsl:value-of select="ns1:id"/>"/>;
<xsl:value-of select="ns1:cLIName"/>"/>;
<xsl:value-of select="ns1:cLINumber"/>;
<xsl:value-of select="ns1:buttonNumber"/>;
<xsl:value-of select="ns1:callType"/>;
<xsl:value-of select="ns1:callUsage"/>;
<xsl:value-of select="ns1:destination"/>;
<xsl:value-of select="ns1:deviceChannel"/>;
<xsl:value-of select="ns1:deviceChannelTypeSpeaker"/>;
<xsl:value-of select="ns1:deviceIdId"/>;
<xsl:value-of select="ns1:displayInCallHistory"/>;
<xsl:value-of select="ns1:duration"/>;
<xsl:value-of select="ns1:e164Destination"/>;
<xsl:value-of select="ns1:eventType"/>;
<xsl:value-of select="ns1:parentUserCDIId"/>;
<xsl:value-of select="ns1:personalPointofContactId"/>;
<xsl:value-of select="ns1:pointofContactId"/>;
<xsl:value-of select="ns1:priority"/>;
<xsl:value-of select="ns1:reasonForDisconnect"/>;
<xsl:value-of select="ns1:resourceAORId"/>;
<xsl:value-of select="ns1:rolloverAppearance"/>;
<xsl:value-of select="ns1:routedDestination"/>;
<xsl:value-of select="ns1:schemaDifference_blob_reserved"/>;
<xsl:value-of select="ns1:schemaDifference_reserved"/>;
<xsl:value-of select="ns1:startTime"/>;
<xsl:value-of select="ns1:trunkBchannel"/>;
<xsl:value-of select="ns1:trunkId"/>;
<xsl:value-of select="ns1:userId"/>
<xsl:text>&#xa;</xsl:text></xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

ns1:NumPagesAvailable,ns1:ReasonCode,ns1:ReasonDescription, ns1:lastModified,ns1:id,ns1:cLIName,ns1:cLINumber,ns1:buttonNumber,ns1:callType,ns1:callUsage,ns1:destination,ns1:deviceChannel,ns1:deviceChannelType,ns1:deviceIdId,ns1:displayInCallHistory,ns1:duration,ns1:e164Destination,ns1:eventType,ns1:parentUserCDIId,ns1:personalPointofContactId,ns1:pointofContactId,ns1:priority,ns1:reasonForDisconnect,ns1:resourceAORId,ns1:rolloverAppearance,ns1:routedDestination,ns1:schemaDifference_blob_reserved,ns1:schemaDifference_reserved,ns1:startTime,ns1:trunkBchannel,ns1:trunkId,ns1:userId
10,REQ_SUCCESS,Fetch Communication History Successful,2019-03-18T00:00:10+00:00:00,290805235,,,1,resource,none,

最佳答案

未经测试,有两件事立即脱颖而出:

  1. 您的模板与 /root 匹配 - 但您的输入没有此类元素;根元素的名称是 nsl:CommunicationHistoryResponse ;
  2. 您使用的是前缀 ns1,但没有先将其绑定(bind)到命名空间。

关于xml - 如何构建与 xsltproc 一起使用的样式表以将 xml 转换为 csv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55486372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com