xsl-list
[Top] [All Lists]

[xsl] Document Function Befuddlement

2008-01-10 09:57:20
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>





--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--