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.
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
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.
I would just use Saxon-PE, and invoke it from a shell script. You could also use Automator.
Related
I am using XSLT (triggered from terminal) to build 2 separate XHTML documents in their own folder structure (e.g. "doc-1-folder", "doc-2-folder"). Each time I build I would like to have a "local" output, but I also added a shared storage folder where I want the outputs to also arrive.
Each trigger of XSLT should therefor produce same output file twice,
one to its local folder and one to shared folder.
The reason for wanting to have duplicate of document builds, is that I will merge some document and would like to perform the merge calling the storage folder.
A short illustration:
Production of doc-1:
/doc-1-folder/myDoc-1.xhtml
/shared/storage/myDoc-1.xhtml
Production of doc-2:
/doc-2-folder/myDoc-2.xhtml
/shared/storage/myDoc-2.xhtml
Would in storage generate:
/shared/storage/myDoc-1.xhtml
/shared/storage/myDoc-2.xhtml
Reading here:
https://www.saxonica.com/documentation10/index.html#!using-xsl/commandline,
it looks like one can only define one output file with the flag "-o".
Is it possible to define several output files? Or would I have to create several XSLT script to process the (identical) output twice?
If you want to do this all within XSLT, you could use the logic
<xsl:variable name="outputDoc">
... generate the output ...
</xsl:variable>
<xsl:result-document href="firstOutput.xml">
<xsl:copy-of select="$outputDoc"/>
</xsl:result-document>
<xsl:result-document href="secondOutput.xml">
<xsl:copy-of select="$outputDoc"/>
</xsl:result-document>
If you're using the Java API for Saxon (s9api) you could be a bit more adventurous and a bit more efficient by writing a ResultDocumentHandler that directs the output to a net.sf.saxon.s9api.TeeDestination that directs it to two separate places on the fly.
I want to link a reference table, (given to me in XML format via link, from a remote server) into another XML file.
For example
<reference>
<listName>countries</listName>
<itemCount>191</itemCount>
<item type="Country" row="1">
<id>1104</id>
<name>TURKEY</name>
</item>
</reference> <!-- Added by edit -->
The thing is that every single item is in different XML, with different link. So I need to link them all and, (in a way) filter the information in a new XML, which to then import to Word Press.
If not XML to XML, then XML to JSON or CSV is ok. Or if there is an software to help me do this.
Thank you in advance.
The best way is to use some online tool where you can load data from URL i found one editor you can use that or use some similar online tool.
Online Ide for xml to json
I have a process to generate html file dynamically, but i dont want to place those html files under the webapp, because if the project are re-deployed, I have to deal with the existing html files(copy out and copy in).
So I'm just wondering if I can place the html files outside of the webapp.
If not, is there any other proper way to meet the requriement?
I'm using tomcat.
Appropriate your help.
Create below dir if not exist:
${CATALINA_HOME}/conf/Catalina/localhost
Create a xml file "article.xml", place the xml under the above path as follows.
${CATALINA_HOME}/conf/Catalina/localhost/article.xml
Add below content to the xml.
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/article" docBase="C:/apps/blog/article" debug="0"
reloadable="true" privileged="true">
</Context>
Start tomcat.
If there's aa.html under the C:/apps/blog/article, use http://localhost:8080/article/aa.html to access the html.
NOTE:
1. Tomcat will take the xml as an web application, and load the resource configed in the xml.
2. No need to create WEB-INF and META-INF for the external folder(C:/apps/blog/article here).
I would like to generate xml file from an extisng csv file using xslt.
Can anybody tell me command to use.
I don't knwo the command to convert the file.
Suppose my csv file named :- source.csv
ouput template :- temp.xsl
command:-
msxsl source.csv temp.xsl -o result.xml
Is this the right command or not?
Here is a XSL file to convert CSV to XML: http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html
To run it from the command line, the instructions say to download Saxon and use:
java -cp saxon.jar net.sf.saxon.Transform -o output.xml -it main csv-to-xml.xslt pathToCSV=file:/C:/dev/test.csv
Here are the parts of that command line explained:
java The java executable (programming language in which Saxon is written
-cp saxon.jar saxon.jar contains the XSLT code, -cp stands for "classpath" and tells java how to find it
-o output.xml Where the output should go. That is result.xml in your example.
-it main csv-to-xml.xslt specify the xslt file (csv-to-xml.xslt) and the entry point within it (main)
pathToCSV=file:/C:/dev/test.csv your input csv file (source.csv in your example, but formatted as a url)
I do not have sufficient reputation to comment on Stephen's answer.
the transform as described is highly dependent on the XSL stylesheet which defines a parameter pathToCSV and a template with the identifier of "main"
the command will not work as Stephen has written it for version 9 of the Home Edition; when I attempt to run the command as written I get a response of "Command line option -o requires a value". However, this format of the command works as of the day of this posting:
java -cp saxon9he.jar net.sf.saxon.Transform -o:csvfile.xml -it:main "csv2xml.xsl" pathToCSV="csvfile.csv"
the linked xsl appears to be buggy (probably hasn't been maintained) and will not correctly transform all csv files (e.g. the csv example from Michael Kay's book). However, it is a good example from which to learn.
First a short task description:
There is an XML file which references a xsl stylesheet which is within a *.dll.
The beginning of this XML looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='res://name_xsl.dll/frameset.xsl'?>
This xml file can be opened and displayed as an HTML within Internet Explorer and only IE.
(The xsl transform the xml to html)
As you can see it references the win32 system folder, in which the dll file is saved.
Referencing with "res://" does work.
But now I do not want to store my dll within the system folder, but under a different folder lets say %ALLUSERSPROFILE% (environment variable) which e.g. on Windows XP is C:\Documents and Settings\All Users or on Win7 C:\Users\Public (Not sure about that one).
How do I reference to the dll lying in that folder?
Is it possible to do this using environment variables, such that it is system independent?
What solution would you recommend.
(All html, xsl data is saved locally within the dll on the local computer.)
So far I have tried to change the reference line to the following:
<?xml-stylesheet type='text/xsl' href='file:///c:/Documents and Settings/All Users/name_xsl.dll/frameset.xsl'?>
I have also tried the same with the root folder c: and even without absolute path having all files (xml and dll) in the same folder.
All attempts without res:// resulted in the following error message:
The system cannot locate the resource specified.
Error processing resource 'file:///C:/Documents and Settings/All Users/name_xsl.dll/...
or 'file:///C:/name_xsl.dll/frameset.xsl'
Could you help me out? Why it does not find the file?
(filenames are fictive)
This is the solution:
<?xml-stylesheet type='text/xsl' href='res://C:%5CDocuments and Settings%5CAll Users%5Cname_xsl.dll/frameset.xsl'?>
Notes:
You MUST use the res:// protocol to access a resource within a file.
File system backslashes can be encoded as %5C . Possibly forward slashes will work as well.
Example:
I tested this example for the file:// protocol, but it should work the same way as the res: protocol. On my system, I have a text file located at:
C:\Program Files\CodeGear\Delphi for PHP\2.0\privacy.txt
I can access this file, by putting into the nav bar of the Windows File Explorer:
file:///%ProgramFiles%/CodeGear/Delphi for PHP/2.0/privacy.txt
Notice backslashes converted to forward slashes, and no need to escape spaces. This has been tested and it works. The equivalent on the res protocol had not been tested, but it should work the same way, except of course that the res protocol is slightly different in that it also includes a resource index number.
Refer http://msdn.microsoft.com/en-us/library/ie/aa767740(v=vs.85).aspx for syntax.