[xsl] Document Function Befuddlement

Subject: [xsl] Document Function Befuddlement
From: "Signature House" <systems@xxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Jan 2008 11:56:58 -0500
Document Function Befuddlement

I'm working on an application where I have to periodically run a number of xml files that I'm given through the same xsl transform.
Conveniently, I also get another xml file that lists the names of all of the data files, so this seemed like the perfect chance to
put the document function to good use (my first time).

I'm on a PC running XP SP2, using IE 7 & xsl 1.0. Below I've included a much reduced test process that I've been using to get it
working - it simply lists the position, name and value of all element nodes.

'day1.xml' & 'day2.xml' are the data files, 'monthly list.xml' is the list of file names and I use 'list nodes.xml' to trigger the
whole thing by loading it into IE.

My befuddlement comes in because I'm getting more output from a more restrictive selection criteria than I am from a less
restrictive selection criteria.

If, in 'monthly process.xsl', I use

<xsl:for-each select="document($monthly_link/@link)/daily//*">

I get, correctly:

Pos Name     Value
--- ----     -----
1   client
2   day      1
3   name     John
4   client
5   day      2
6   name     Margaret

However, this doesn't show the daily nodes, which I wanted included also, so I tried:

<xsl:for-each select="document($monthly_link/@link)//*">

I get, unexpectedly:

Pos Name     Value
--- ----     -----
1   daily
2   client
3   day      1
4   name     John

What I expected (and wanted) from the use of //* is:

Pos Name     Value
--- ----     -----
1   daily
2   client
3   day      1
4   name     John
5   daily
6   client
7   day      2
8   name     Margaret

Would someone please explain why this is happening and what I should do to get the results I need?

Thanks in advance

Mike McBee
Signature House

monthly process.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/">
 <table border="1">
  <xsl:variable name="monthly_link" select="document('monthly list.xml')/monthly/day"/>
  <xsl:for-each select="SEE ABOVE">
    <td><xsl:number value="position()" format="1"/></td>
    <td><xsl:value-of select="name(self::node())"/></td>
    <td><xsl:value-of select="normalize-space(text())"/></td>

list nodes.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="monthly process.xsl"?>

monthly list.xml
<?xml version="1.0"?>
 <day link="day1.xml"/>
 <day link="day2.xml"/>

<?xml version="1.0"?>

<?xml version="1.0"?>

Current Thread