[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: document() loops

Subject: Re: document() loops
From: "Laura Jenkins" <xsl_list@xxxxxxxxxxx>
Date: Fri, 13 Sep 2002 08:50:26 +0000
laura jenkins
Actually the question in the previous thread was a bit different.and i was able to solve it.The previous case was i was using one of the XMLs as main XML and passing the other xml files as parameters.. that was working fine. But then the decision changed to have one xml file with all the xml file locations as child elements like..
**** mainxml.xml****
<?xml version="1.0"?>
<!-- all the below xml files( univ1.xml.. etc are in the same directory as mainxml.xml
-->
<univ-xml-list>
<univ-xml>univ1.xml</univ-xml>
<univ-xml>univ2.xml</univ-xml>
<univ-xml>univ3.xml</univ-xml>
</univ-xml-list>
and the xsl should now go through each of the univ xmls and merge them.
What I thot of doing was first go through one of the xmls( the first one for example ) and construct the elements.


<xsl:for-each select="document(/univ-xml-list/univ-xml[1])">
<xsl:variable name = "element-name" select="name(.)"/>
<xsl:element name="$element-name">


</xsl:element> </xsl:for-each> this will create all the elements that are in the first elements..

now the next thing what i want to do is ..
run a for-each against the mainxml.xml and plug in the element data into the above created element "where" the element name equals the name of the element from the first for-loop


that is..
<xsl:for-each select="document(/univ-xml-list/univ-xml[1])">
<xsl:variable name = "element-name" select="name(.)"/>
<xsl:element name="$element-name">
<xsl:for-each select="document(/univ-xml-list/univ-xml)/university-records">
<xsl:copy-of select="*[name(.) = $element-name]"/>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
my intention above was to fill in the data elements from all the xml files specified in the mainxml.xml into the element created using the first xml( all xmls will have same structure)


But this does not work..
one of the univ xmls is as  follows
<?xml version="1.0"?>
<university-records>
<univ-ids>
<univ id = "NSU">
<name> Newyork State University</name>
<location> Newyork </location>
</univ>
<univ id = "BU">
<name> Belmont University</name>
<location> Belmont </location>
</univ>
</univ-ids>
<university-results>
<university univ-id = "NSU">70%</university>
<university univ-id = "BU">60%</university>
</university-results>
</university-records>

What i noticed was.. When the for-each is processing one document(),
it is not able to process any other document.. and also fails to recognize the elements from the mainxml.


I do not know if there is any other way of doing this?
Thanks

From: David Carlisle <davidc@xxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  document() loops
Date: Thu, 12 Sep 2002 17:41:00 +0100

You say you want to merge the files but your two loops only have one
node each (the root nodes of the first and second documents respectively).
So as written you don't really need a for-each at all as there is only
one node being used.

I posted some code before (I just noticed this is the same thread as the
earlier question) does that not do what you expect?

David


_____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Scanning Service. For further information visit http://www.star.net.uk/stats.asp or alternatively call Star Internet for details on the Virus Scanning Service.

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.