RE: [xsl] Document Function Befuddlement

Subject: RE: [xsl] Document Function Befuddlement
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Thu, 10 Jan 2008 11:02:48 -0600
I'm... not too sure about the genuine fix for the problem, but this
might be an acceptable workaround:

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

~ Scott


-----Original Message-----
From: Signature House [mailto:systems@xxxxxxxxxxxxxxxxxx]
Sent: Thursday, January 10, 2008 10:57 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Document Function Befuddlement

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"/>
  <tr><td>Pos</td><td>Name</td><td>Value</td></tr>
  <xsl:for-each select="SEE ABOVE">
   <tr>
    <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>
   </tr>
  </xsl:for-each>
 </table>
</xsl:template>
</xsl:stylesheet>


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


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


day1.xml
--------
<?xml version="1.0"?>
<daily>
 <client>
  <day>1</day>
  <name>John</name>
 </client>
</daily>


day2.xml
--------
<?xml version="1.0"?>
<daily>
 <client>
  <day>2</day>
  <name>Margaret</name>
 </client>
</daily>

Current Thread