0

I have the following XML:

<page id="12095325">
 <name>DUMMY TEST</name>
 <description>Includes in- & outbound dial statistics</description>
 <server>reg6699cic01</server>
 <created>2015/02/19 11:57:05 AM</created>
 <adhocmessage/>
<workgroups>
<workgroup>
 <name>SSC_UK_Office_All</name>
 <agents>24</agents>
 <agentsavailable>0</agentsavailable>
 <agentsloggedin>16</agentsloggedin>
 <longestavailable>-</longestavailable>
 <longestoutbound>4d 09:38:18</longestoutbound>
 <longestinbound>00:00:34</longestinbound>
 <longestnonacd>-</longestnonacd>
 <numbernonacd>0</numbernonacd>
 <numberoninbound>1</numberoninbound>
 <numberoninboundinacw>3</numberoninboundinacw>
 <numberonoutbound>4</numberonoutbound>
 <numberonoutboundinacw>1</numberonoutboundinacw>
 <agentstatus/>
 </workgroup>
 </workgroups>
<agentstats>
<agent>
 <name>Aaron.House</name>
 <firstname>Aaron</firstname>
 <lastname>House</lastname>
 <extension>902030</extension>
<station/>
 </agent>
  </agentstats>
  </page>

When I apply a template that matches the <agentstats> I do get information from the whole xml rather than the agentstats section only?

I try to understand why. This is the xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                          xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-    prefixes="msxsl">

  <xsl:param name="row-count" select="3"/>
  <xsl:output method="html" encoding="utf-8" indent="yes"/>

  <xsl:template match="agentstats">
<!--    <xsl:call-template name="agents"/>     -->
  </xsl:template>

  <xsl:template name="agents">
    <table border="1">
        <tr>
          <td>Agent Name</td>
          <td>Station</td>
          <td>Status</td>
    </tr>
  <xsl:for-each select="agent">
    <tr>  
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="station"/></td>
      <td><xsl:value-of select="currentstatus"/></td>
    </tr>      
    </xsl:for-each>
    </table>
  </xsl:template>
</xsl:stylesheet>

And this is the output generated:

enter image description here

I would not expect to see the first line:

DUMMY TEST Includes in- & outbound dial statistics reg6699cic01 2015/02/19 11:57:05 AM SSC_UK_Office_All 24 0 16 - 4d 09:38:18 00:00:34 - 0 1 3 4 1 

but rather the table only

Any ideas what's happening here? Regards

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
NiteOwls
  • 189
  • 4
  • 15
  • I wouldn't expect this to work at all as your input data is not well-formed XML (it contains an un-escaped `&` in the `description`). – Ian Roberts Feb 20 '15 at 10:20
  • And your XSLT is malformed too: `exclude-result- prefixes` is not a valid attribute name (contains spaces). – michael.hor257k Feb 20 '15 at 10:36

2 Answers2

0

First of all, your xml and xslt files have 2 issues (as several commentors have pointed out):

  • (xml): The & needs to be encoded: &#x26;.
  • (xslt): Attribute names mustn't contain whitespace ( exclude-result-prefixes="msxsl" in the root element )

Back to the problem at hand: One of the default templates seems to apply. You may specify a different default template for processing text() - do nothing instead of copying:

    <!-- ... your stylesheet --> 
    <xsl:template match="text()"/>
</xsl:stylesheet>

Have a look at this SO answer for details on default templates in xslt.

Btw, given your output, is the xml you posted complete ?

Community
  • 1
  • 1
collapsar
  • 17,010
  • 4
  • 35
  • 61
0

What you see is most likely the result of the built-in template rules being applied. I say "most likely" because, as was pointed out in the comments, your issue cannot be reproduced using the code you have posted.

The only template that you have that's actually doing anything, is:

      <xsl:template match="agentstats">
<!--    <xsl:call-template name="agents"/>     -->
  </xsl:template>

It suppresses anything in the agentstats nodes and their descendants from appearing in the output. So you don't see, for example, the text "Aaron.House".

All the other nodes are handled by the default built-in template, which copies the text (and only the text).

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51