xmlxsltxslt-1.0

Looping through nested nodes with XSLT, without specifying attribute


I'm having some trouble transforming some XML. I have a pretty generic template, and everything is coming in above a certain level. When I get to the first instance of nested objects, my transformer doesn't give me any output.

Here's what the XML looks like:

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

I'm basically trying to just load these results into a simple Bootstrapped table. My XSL for that table looks like this:


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

Sorry for the dense lines. Basically what I'm experiencing here is all the regular nodes at the '''ININ.Workgroup''' level are showing up, but when I try to access the material in '''ININ.Queue_Interval''' node, they come back incorrcectly (N/A or 0 where there should be values). I've tried to put in the Attribute of @CurrentShift in the XPATH, like <xsl:value-of select="ININ.Queue_Interval/@Name=CurrentShift/ININ.Workgroup_InteractionsEntered"/> but it still comes in as all 0s and N/As.

In the full XML, there are 30 or so more ININ.People.WorkgroupStats_Workgroup nodes, so I'm trying to do this within one big loop that hits both the content at the Workgroup Level and then at the Queue_Interval level, but I'm not sure if that's the best way to go about it.

I've also tried some abridged XPATH, i.e.

<xsl:value-of select="./ININ.Workgroup_InteractionsWaiting" /> 

But again I'm just having a hard time narrowing down the problem. Thanks for your insight (and patience)!

Here's the transformed XML(HTML?) and the incorrect values:

enter image description here

I feel like it might be just looping the first value it finds, but not certain.


Solution

  • Assuming that your instruction:

    <xsl:for-each select="IcServer/ININ.Workgroup/ININ.People.WorkgroupStats_Workgroup">
    

    works, the correct expression to get a value from within the ININ.Queue_Interval section would be:

    <xsl:value-of select="ININ.Queue_Interval/ININ.Workgroup_InteractionsEntered"/>
    

    This is assuming there is only one such section within the current ININ.People.WorkgroupStats_Workgroup. If there can be more, and you want to specify the one you want by its name attribute, then use:

    <xsl:value-of select="ININ.Queue_Interval[@name='CurrentShift']/ININ.Workgroup_InteractionsEntered"/>
    

    Here's a demo using a minimal example like the one you should have used:
    https://xsltfiddle.liberty-development.net/naZXVEH

    If you're getting a different result, then there's something wrong with your processing chain.