P
Phil
Hi everybody,
I am a XSLT beginner and the following problem really makes me crazy !
I have a main "contacts.xml" document which contains references to
several contact data XML files.
My aim is to process the contacts in a single-pass XSLT process.
That is why the "document()" function is what I need.
I call the "document()" XPath function from a "for-each" instruction.
Inside the "for-each" loop, I process the included elements : you will
notice that the referenced filenames are ordered from "contact1" to
"5".
I would like to preserve that order.
My "for-each" or my "document()" call seems to change the reference
order I specified as you can see on my program output :
Ouput:
No. 2: Johny
No. 1: Jimmy
No. 5: Bill
No. 3: Paul
No. 4: Keith
I ran my XSLT through many processors (Xalan, MSXML ...) and the
result is (hopefully !) always the same.
Before this, I understood that if no "sort" instruction was specified,
the order was always the document order.
=> Can somebody explain to me why the XSLT processor change the
include order and how element are ordered ?
Thanks in advance.
Please find my XSLT/XML file below
----------------------------------
simple-document.xslt
--------------------
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
Ouput:
<xsl:for-each select="document(/contacts/entry/@filename)">
No. <xsl:value-of select="/contact/no"/>: <xsl:value-of
select="/contact/name"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
contacts.xml
------------
<?xml version="1.0"?>
<contacts>
<entry filename="contact1.xml"/>
<entry filename="contact2.xml"/>
<entry filename="contact3.xml"/>
<entry filename="contact4.xml"/>
<entry filename="contact5.xml"/>
</contacts>
contact1.xml
------------
<?xml version="1.0"?>
<contact>
<name>Jimmy</name>
<company>IBM</company>
<email>[email protected]</email>
<no>1</no>
</contact>
contact2.xml
------------
<?xml version="1.0"?>
<contact>
<name>Johny</name>
<company>Compaq</company>
<email>[email protected]</email>
<no>2</no>
</contact>
contact3.xml
------------
<?xml version="1.0"?>
<contact>
<name>Paul</name>
<company>Hewlet-Packard</company>
<email>[email protected]</email>
<no>3</no>
</contact>
contact4.xml
------------
<?xml version="1.0"?>
<contact>
<name>Keith</name>
<company>Nortel</company>
<email>[email protected]</email>
<no>4</no>
</contact>
contact5.xml
------------
<?xml version="1.0"?>
<contact>
<name>Bill</name>
<company>Microsoft</company>
<email>[email protected]</email>
<no>5</no>
</contact>
I am a XSLT beginner and the following problem really makes me crazy !
I have a main "contacts.xml" document which contains references to
several contact data XML files.
My aim is to process the contacts in a single-pass XSLT process.
That is why the "document()" function is what I need.
I call the "document()" XPath function from a "for-each" instruction.
Inside the "for-each" loop, I process the included elements : you will
notice that the referenced filenames are ordered from "contact1" to
"5".
I would like to preserve that order.
My "for-each" or my "document()" call seems to change the reference
order I specified as you can see on my program output :
Ouput:
No. 2: Johny
No. 1: Jimmy
No. 5: Bill
No. 3: Paul
No. 4: Keith
I ran my XSLT through many processors (Xalan, MSXML ...) and the
result is (hopefully !) always the same.
Before this, I understood that if no "sort" instruction was specified,
the order was always the document order.
=> Can somebody explain to me why the XSLT processor change the
include order and how element are ordered ?
Thanks in advance.
Please find my XSLT/XML file below
----------------------------------
simple-document.xslt
--------------------
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
Ouput:
<xsl:for-each select="document(/contacts/entry/@filename)">
No. <xsl:value-of select="/contact/no"/>: <xsl:value-of
select="/contact/name"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
contacts.xml
------------
<?xml version="1.0"?>
<contacts>
<entry filename="contact1.xml"/>
<entry filename="contact2.xml"/>
<entry filename="contact3.xml"/>
<entry filename="contact4.xml"/>
<entry filename="contact5.xml"/>
</contacts>
contact1.xml
------------
<?xml version="1.0"?>
<contact>
<name>Jimmy</name>
<company>IBM</company>
<email>[email protected]</email>
<no>1</no>
</contact>
contact2.xml
------------
<?xml version="1.0"?>
<contact>
<name>Johny</name>
<company>Compaq</company>
<email>[email protected]</email>
<no>2</no>
</contact>
contact3.xml
------------
<?xml version="1.0"?>
<contact>
<name>Paul</name>
<company>Hewlet-Packard</company>
<email>[email protected]</email>
<no>3</no>
</contact>
contact4.xml
------------
<?xml version="1.0"?>
<contact>
<name>Keith</name>
<company>Nortel</company>
<email>[email protected]</email>
<no>4</no>
</contact>
contact5.xml
------------
<?xml version="1.0"?>
<contact>
<name>Bill</name>
<company>Microsoft</company>
<email>[email protected]</email>
<no>5</no>
</contact>