我在转换一些XML时遇到了一些困难。我有一个相当通用的模板,所有的东西都超过了一定的水平。当我进入嵌套对象的第一个实例时,我的转换器不会给我任何输出。
以下是XML的样子:
<?xml version="1.0" encoding="utf-8"?>
<Statistics>
<IcServer name="Apsep00840">
<ININ.Workgroup>
<ININ.People.WorkgroupStats_Workgroup name="Campaign 1">
<ININ.Workgroup_NumberAvailableForACDInteractions>11</ININ.Workgroup_NumberAvailableForACDInteractions>
<ININ.Workgroup_LongestAvailable>00:09:21</ININ.Workgroup_LongestAvailable>
<ININ.Workgroup_OnInboundACDInteractions>0</ININ.Workgroup_OnInboundACDInteractions>
<ININ.Workgroup_OnInboundACW>0</ININ.Workgroup_OnInboundACW>
<ININ.Workgroup_LongestInboundACDInteraction>N/A</ININ.Workgroup_LongestInboundACDInteraction>
<ININ.Workgroup_InteractionsWaiting>42</ININ.Workgroup_InteractionsWaiting>
<ININ.Workgroup_LongestWaitTime>00:00:42</ININ.Workgroup_LongestWaitTime>
<ININ.Workgroup_LongestOnHoldTime>N/A</ININ.Workgroup_LongestOnHoldTime>
<ININ.Workgroup_AgentsLoggedInAndActivated>79</ININ.Workgroup_AgentsLoggedInAndActivated>
<ININ.Queue_Interval name="CurrentShift">
<ININ.Workgroup_InteractionsEntered>9602</ININ.Workgroup_InteractionsEntered>
<ININ.Workgroup_InteractionsAnswered>9578</ININ.Workgroup_InteractionsAnswered>
<ININ.Workgroup_InteractionsAbandoned>25</ININ.Workgroup_InteractionsAbandoned>
<ININ.Workgroup_AverageWaitTime>00:00:01</ININ.Workgroup_AverageWaitTime>
<ININ.Workgroup_AverageHoldTime>00:00:01</ININ.Workgroup_AverageHoldTime>
<ININ.Workgroup_AverageTalkTime>00:02:17</ININ.Workgroup_AverageTalkTime>
<ININ.Workgroup_ServiceLevelTarget>N/A</ININ.Workgroup_ServiceLevelTarget>
<ININ.Workgroup_AbandonedRateTarget>N/A</ININ.Workgroup_AbandonedRateTarget>
</ININ.Queue_Interval>
</ININ.People.WorkgroupStats_Workgroup>
<ININ.People.WorkgroupStats_Workgroup name="Campaign 2">
<ININ.Workgroup_NumberAvailableForACDInteractions>11</ININ.Workgroup_NumberAvailableForACDInteractions>
<ININ.Workgroup_LongestAvailable>00:09:21</ININ.Workgroup_LongestAvailable>
<ININ.Workgroup_OnInboundACDInteractions>0</ININ.Workgroup_OnInboundACDInteractions>
<ININ.Workgroup_OnInboundACW>0</ININ.Workgroup_OnInboundACW>
<ININ.Workgroup_LongestInboundACDInteraction>N/A</ININ.Workgroup_LongestInboundACDInteraction>
<ININ.Workgroup_InteractionsWaiting>0</ININ.Workgroup_InteractionsWaiting>
<ININ.Workgroup_LongestWaitTime>N/A</ININ.Workgroup_LongestWaitTime>
<ININ.Workgroup_LongestOnHoldTime>N/A</ININ.Workgroup_LongestOnHoldTime>
<ININ.Workgroup_AgentsLoggedInAndActivated>79</ININ.Workgroup_AgentsLoggedInAndActivated>
<ININ.Queue_Interval name="CurrentShift">
<ININ.Workgroup_InteractionsEntered>5171</ININ.Workgroup_InteractionsEntered>
<ININ.Workgroup_InteractionsAnswered>5161</ININ.Workgroup_InteractionsAnswered>
<ININ.Workgroup_InteractionsAbandoned>10</ININ.Workgroup_InteractionsAbandoned>
<ININ.Workgroup_AverageWaitTime>00:00:01</ININ.Workgroup_AverageWaitTime>
<ININ.Workgroup_AverageHoldTime>00:00:01</ININ.Workgroup_AverageHoldTime>
<ININ.Workgroup_AverageTalkTime>00:02:28</ININ.Workgroup_AverageTalkTime>
<ININ.Workgroup_ServiceLevelTarget>N/A</ININ.Workgroup_ServiceLevelTarget>
<ININ.Workgroup_AbandonedRateTarget>N/A</ININ.Workgroup_AbandonedRateTarget>
</ININ.Queue_Interval>基本上,我只是尝试将这些结果加载到一个简单的引导表中。该表的XSL如下所示:
<table class="table table-hover table-dark table-striped">
<!-- Colspan for separating header -->
<col>
<colgroup span="2"></colgroup>
<colgroup span="2"></colgroup>
</col>
<thead>
<tr>
<th rowspan="2" style="text-align: left">Workgroup</th>
<th style="text-align: center" class="border" colspan="9">Workgroup Stats</th>
<th style="text-align: center" class="border" colspan="9">Queue Stats</th>
</tr>
<span>
<th class="border-left" scope="col">Available for ACD Interactions</th>
<th scope="col">Longest Available</th>
<th scope="col">On Inbound ACD Interactions</th>
<th scope="col">On Inbound ACW</th>
<th scope="col">Longest Inbound ACD Interaction</th>
<th scope="col">Interactions Waiting</th>
<th scope="col">Longest Interaction Waiting</th>
<th scope="col">Longest Hold Time</th>
<th class="border-right" scope="col">Logged on and Activated</th>
<th scope="col">Intrs Received </th>
<th scope="col">Intrs Answered</th>
<th scope="col">Intrs Abandoned</th>
<th scope="col">Avg Wait</th>
<th scope="col">Avg Hold</th>
<th scope="col">Avg Talk</th>
<th scope="col">Svc Lvl Tgt</th>
<th class="border-right" scope="col">Abandon Tgt</th>
</span>
<tr>
</tr>
</thead>
<tbody class="border-bottom">
<xsl:for-each select="IcServer/ININ.Workgroup/ININ.People.WorkgroupStats_Workgroup">
<tr class="border-bottom">
<td style="text-align: left">
<xsl:value-of select="@name"/>
</td>
<td class="border-left">
<xsl:value-of select="ININ.Workgroup_NumberAvailableForACDInteractions"/>
</td>
<div style="text-align: right">
<td>
<xsl:value-of select="ININ.Workgroup_LongestAvailable"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_OnInboundACDInteractions"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_OnInboundACW"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_LongestInboundACDInteraction"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_InteractionsWaiting"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_LongestWaitTime"/>
</td>
<td>
<xsl:value-of select="ININ.Workgroup_LongestOnHoldTime"/>
</td>
<td class="border-right">
<xsl:value-of select="ININ.Workgroup_AgentsLoggedInAndActivated"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_InteractionsEntered"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_InteractionsAnswered"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_InteractionsAbandoned"/>
</td>
<td class="border-right">
<xsl:value-of select="//ININ.Workgroup_AverageWaitTime"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_AverageHoldTime"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_AverageTalkTime"/>
</td>
<td>
<xsl:value-of select="//ININ.Workgroup_ServiceLevelTarget"/>
</td>
<td class="border-right">
<xsl:value-of select="//ININ.Workgroup_AbandonedRateTarget"/>
</td>
</div>
</tr>
</xsl:for-each>
</tbody>
</table>抱歉线路太密集了。基本上,我在这里体验的是‘’IN.Workgroup‘’级别上的所有常规节点都会显示出来,但是当我试图访问‘IN.Queue_Interval’‘节点中的材料时,它们会不相关地返回(N/A或0,其中应该有值)。我尝试在XPATH中添加@CurrentShift的属性,就像<xsl:value-of select="ININ.Queue_Interval/@Name=CurrentShift/ININ.Workgroup_InteractionsEntered"/>一样,但它仍然以所有的0和N/As的形式出现。
在完整的XML中,有30个左右的ININ.People.WorkgroupStats_Workgroup节点,所以我尝试在一个大循环中实现这一点,这个循环在工作组级别和Queue_Interval级别都可以访问内容,但我不确定这是否是最好的方法。
我还尝试了一些简化的XPATH,即
<xsl:value-of select="./ININ.Workgroup_InteractionsWaiting" /> 但我还是很难缩小问题的范围。感谢您的洞察力(和耐心)!
以下是转换后的XML(HTML?)以及不正确的值:

我觉得它可能只是循环它找到的第一个值,但不确定。
发布于 2020-03-13 15:52:36
很难验证您的代码,因为它是不完整的(而且太长了-请参阅https://stackoverflow.com/help/minimal-reproducible-example)。
假设你的指示:
<xsl:for-each select="IcServer/ININ.Workgroup/ININ.People.WorkgroupStats_Workgroup">工作时,从ININ.Queue_Interval部分中获取值的正确表达式是:
<xsl:value-of select="ININ.Queue_Interval/ININ.Workgroup_InteractionsEntered"/>这是假设在当前的ININ.People.WorkgroupStats_Workgroup中只有一个这样的部分。如果可以有更多,并且希望通过其name属性指定所需的属性,则请使用:
<xsl:value-of select="ININ.Queue_Interval[@name='CurrentShift']/ININ.Workgroup_InteractionsEntered"/>下面是一个使用最小示例的演示,如您应该使用的示例:
https://xsltfiddle.liberty-development.net/naZXVEH
如果你得到了不同的结果,那么你的处理链就有问题了。
https://stackoverflow.com/questions/60663187
复制相似问题