Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 8th, 2010, 06:43 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default Multiple Inputs: collections

I am using Saxon and XSLT 2.0. I have a document that lists all the files we want to process:

<files>
<file loc="path/filename.xml"/>
<file loc="path/filename.xml"/>
<file loc="path/filename.xml"/>
<file loc="path/filename.xml"/>
</files>

In the XSL, I need to process each file. Each file can have a different path. Is it possible to loop thru each <file> and process the nodes?

<xsl:for-each select="doc(file/@loc)">

<!-- xslt instructions -->


</xsl:for-each>

Or is there a better approach?
 
Old March 8th, 2010, 06:46 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Or can you use something like <apply-templates select="doc(file/@loc)"/>?
 
Old March 8th, 2010, 06:52 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A call on doc() takes a single URI and returns a single document.

To get multiple documents from multiple URIs, you could use select="document(loc/@href)". Another advantage of using document() here rather than doc() is that where the argument is a node, and the URI is relative, it is treated as being relative to the URI of that node (i.e. to the document containing the URIs), not relative to the stylesheet.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old March 8th, 2010, 06:58 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

To clarify, the following would work?

<xsl:template match="backbone">
<apply-templates select="document(file/@loc)"/>
</xsl:template>

<xsl:template match="document(file/@loc)">
<!-- instructions here -->
</xsl:template>
 
Old March 9th, 2010, 09:09 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If the primary input file you showed in your original post has a 'files' root element then you could do e.g.
Code:
<xsl:template match="files">
  <xsl:apply-templates select="document(file/@doc)/node()"/>
</xsl:template>
and then you would need to write templates matching the nodes in those documents e.g. if the root elements in those documents are named 'foo' then you would use e.g.
Code:
<xsl:template match="foo">
  ...
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
1 form for multiple inputs Vince_421 Access VBA 2 February 6th, 2007 04:06 AM
FLASH User Inputs IP076 Flash (all versions) 1 January 5th, 2007 12:23 AM
CHECK_SUM returns same value for diff. inputs joxa83 SQL Server 2000 1 July 6th, 2006 07:08 AM
command line inputs for xsl rameshnarayan XSLT 3 August 4th, 2005 05:10 AM
Multiple inputs on same page kev_79 Access 3 July 8th, 2003 11:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.