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 August 28th, 2012, 08:12 AM
Authorized User
 
Join Date: Aug 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default Processing XSLT on multiple files

Hi,

I want to run an XSLT script to pull some text from within a certain element(s) of multiple XML files. I'm sure i can work out the code to select the element i need and grab the text from within, but how do i run the XSLT on multiple XML source files?

Is this possible without extensive coding knowledge? I'm a c# beginner as well as XSLT but what i thought would be a fairly easy task is proving out of my depth.

Thanks in advance for any pointers.
 
Old August 28th, 2012, 09:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can load a source document using the document() function if you know its URI. You don't say how the multiple source documents will be identified, so it's hard to give you any more specific advice.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 28th, 2012, 10:08 AM
Authorized User
 
Join Date: Aug 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank for your response Michael. Your expertise is appreciated.

This is really a general query as I work with hundreds of XML files at the same time, and to be able to run a query on a batch would be incredibly useful.

For example, I have a bunch of XML files containing aircraft maintenance procedures - this is my line of work. What i would like to do is to be able to extract all the necessary support equipment and consumables from all these files to compile a list (or single XML file) of what is required to complete all the procedures.

So within the individual procedures, the support equipment is contained in <supequip> elements, and consumables are contained within <supply> elements.

I would like to be able to point to a folder containing all my XML files, and run the XSLT so that the output is a complete list of equipment and consumables.

Hope this makes things a bit clearer, and thank you again.
 
Old August 28th, 2012, 10:15 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Assuming you use Saxon 9 for your XSLT (2.0) processing you can use the collection function, see http://www.saxonica.com/documentatio...ollections.xml. So
Code:
<xsl:apply-templates select="collection('file:///C:/dir/subir?select=*.xml')//supequip"/>
processes the supequip elements in all .xml files in that directory C:/dir/subir.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 28th, 2012, 10:21 AM
Authorized User
 
Join Date: Aug 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank you Martin, I will try that later ... it looks like it could be exactly what I'm looking for.

Assuming I can work it out, it will be extremely useful for various queries.

Thanks again.
 
Old August 28th, 2012, 10:45 AM
Authorized User
 
Join Date: Aug 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Martin, it has just occurred to me that your solution actually calls the collection of files from the XSLT itself. I wasn't expecting to see that.

My assumption was that I would point to the directory of files when executing Saxon from the command line.

Using your method, what would I point to as the source file when executing?
 
Old August 28th, 2012, 10:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

With Saxon (and other XSLT 2.0 processors I believe) you can pass an initial template name in, rather than passing a source document.

saxon -it "main"

will run the following template:

<xsl:template name="main"><!-- run me first --> ...
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to process multiple input xml files with a single xslt ? Divya XSLT 12 October 9th, 2018 03:01 AM
Help needed transforming XML using multiple XSLT files. LenovoThinkCentre XSLT 2 August 28th, 2012 06:38 AM
parse multiple .XSD files with XSLT chaostimmy XSLT 12 August 17th, 2009 12:06 PM
Array like processing (Xpath 1 / XSLT 1) akentanaka XSLT 1 July 2nd, 2008 02:22 AM
XSLT to make multiple hyperlinked HTML files dai.hop XSLT 1 January 11th, 2006 03:05 PM





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