0
votes

I have a folder of several hundred XML files that I would like to convert into a folder of HTML files. I've created an XSLT that works in w3schools.com's XSLT tester, but I'm not sure how to apply that stylesheet across hundreds of XML documents. My XML looks like this (and the only nodes I'm interested in are title, author, and lyrics):

<?xml version='1.0' encoding='utf-8'?>
<song xmlns="http://openlyrics.info/namespace/2009/song" version="0.8" createdIn="OpenLP     2.0.1" modifiedIn="OpenLP 2.0.1" modifiedDate="2012-03-14T02:21:52">
  <properties>
    <titles>
      <title>Amazing Grace</title>
    </titles>
    <authors>
      <author>John Newton</author>
    </authors>
  </properties>
  <lyrics>
    <verse name="v1">
      <lines>Amazing grace, how sweet the sound<br/>That saved a wretch like me<br/>I once was lost, but now am found<br/>Was blind but now I see</lines>
    </verse>

A couple questions about this:

1) Might it be better to use XQuery since I'm only interested in extracting a few lines per XML file?

2) Regardless of XSLT/XQuery, how can I implement a solution that converts a folder of XML files (without manually editing each one to call upon the XSL stylesheet)? I'm running OS X 10.8.4.

Thanks in advance.

2
You should used collection() function of xslt2.0 to apply your stylesheet accross hundreds of xml Documents. For more understanding you may follow xmlplease.com/collection. I am nut sure about HTML, what you want to convert. Are you just want to rename your xml to html extention or you want to create multiple html file depending on your XML input files. - Navin Rawat
I would use XSLT 2.0 and the collection() function like Navin suggested. This may cause issues with memory consumption though. You can solve this by using Saxon's extension function saxon:discard-document. I can add an example if it would help. - Daniel Haley

2 Answers

0
votes

Just write your own shell script using the xsltproc command. This is what I used successfully for XSLT batch processing.

Or just open a shell, cd to the folder with the XML files and then enter the following two commands:

mkdir results
xsltproc -o results/ path/to/stylesheet.xslt *.xml
0
votes
  1. I think XQuery would be more convenient if you had all of your XML in a database, but on the filesystem XSLT may be simpler.

  2. I would just use Saxon-PE, and invoke it from a shell script. You could also use Automator.