使用XSLT遍历嵌套节点,但未指定属性

问题描述 投票:0回答:1

我在转换某些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>

我基本上是试图将这些结果加载到简单的Bootstrapped表中。我对该表的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>

对不起,线条浓密。基本上,我在这里遇到的是“''ININ.Workgroup'''级别上的所有常规节点都出现了,但是当我尝试访问“''ININ.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?)和不正确的值:

enter image description here

我觉得它可能只是循环找到的第一个值,但不确定。

我在转换某些XML时遇到麻烦。我有一个非常通用的模板,所有东西都超过了一定水平。当我到达嵌套对象的第一个实例时,我的转换器...

xml xslt xslt-1.0
1个回答
0
投票

很难验证您的代码,因为它不完整(而且时间太长-参见https://stackoverflow.com/help/minimal-reproducible-example)。

© www.soinside.com 2019 - 2024. All rights reserved.