Document Function Befuddlement - results
As you may remember, I was getting unexpected results when I tried running a
transform against multiple XML input files (unexpected
in that I wasn't getting the same results that I got when I ran the transform
against the XML files individually).
I was using statements in this form in IE7:
<xsl:template match="/">
<xsl:variable name="file_list" select="document('file name
list.xml.xml')/monthly/day"/>
<xsl:for-each select="document($file_list/@link)//*">
and other variations, resulting in either absent or extra lines appearing in
the result.
Michael Kay remarked that it looked like a bug in the IE7 processor and
suggested that I try another processor. I did, and the above
coding worked fine - IE was the problem.
After experimenting (a lot), I found that this worked correctly in IE7:
<xsl:variable name="file_list" select="document('file name list.xml')//@link"/>
<xsl:for-each select="document($file_list)">
<xsl:for-each select="//*|//@*">
My thanks for your help, this list is a great resource.
Mike McBee
Signature House
systems(_at_)signaturehouse(_dot_)net
www.signaturehouse.net
304-842-3386
Element and Attribute List, by File
Position Level Path Name Value Type
-------- ----- -------------- ------ -------- ---------
1 1 / daily element
2 2 /daily/ client element
3 2 /daily/client/ s m attribute
4 3 /daily/client/ day 1 element
5 3 /daily/client/ name John element
1 1 / daily element
2 2 /daily/ client element
3 2 /daily/client/ s f attribute
4 3 /daily/client/ day 2 element
5 3 /daily/client/ name Margaret element
listnodes.xsl
-------------
<?xml version="1.0"?>
<xsl:template match="/">
<xsl:variable name="file_list" select="document('file name list.xml')//@link"/>
<table border="1">
<tr><td colspan="6">Element and Attribute List, by File</td></tr>
<tr><td>Position</td><td>Level</td><td>Path</td>
<td>Name</td><td>Value</td><td>Type</td></tr>
<xsl:for-each select="document($file_list)">
<xsl:for-each select="//*|//@*">
<xsl:if test="''=''">
<tr>
<!-- Get the sequential position in the node set -->
<td><xsl:number value="position()"/></td>
<!-- Get the level in the tree -->
<td><xsl:value-of select="count(ancestor-or-self::*)"/></td>
<!-- Get the path -->
<td>
<xsl:for-each select="ancestor::node()">
<xsl:value-of select="name()"/>
<xsl:text>/</xsl:text>
</xsl:for-each>
</td>
<!-- Get the node name -->
<td><xsl:value-of select="name(self::node())"/></td>
<xsl:choose>
<xsl:when test="self::*">
<!-- For an element node, get the value and indicate type -->
<td><xsl:value-of select="normalize-space(text())"/></td>
<td><xsl:value-of select="'element'"/></td>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="count(.|../@*)=count(../@*)">
<!-- For an attribute, get the value and indicate type -->
<td><xsl:value-of select="normalize-space(.)"/></td>
<td><xsl:value-of select="'attribute'"/></td>
</xsl:when>
<xsl:otherwise>
<!-- For anything else -->
<td><xsl:value-of select="normalize-space(.)"/></td>
<td><xsl:value-of select="'other'"/></td>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
launch list nodes.xml
---------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href=".//list nodes.xsl"?>
<null>null</null>
file name list.xml
------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"?>
<monthly>
<day link="day1.xml"/>
<day link="day2.xml"/>
</monthly>
day1.xml
--------
<?xml version="1.0"?>
<daily>
<client s="m">
<day>1</day>
<name>John</name>
</client>
</daily>
day2.xml
--------
<?xml version="1.0"?>
<daily>
<client s="f">
<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>
--~--