ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello all, glad this forum is here because I'm sick of googling and LQ.org is my favorite forum for answers. Here's the short of it:
I need to transform XML documents from one schema to another using XSLT. The XML documents in question have their own XML namespaces in the root node.
Using oXygen's XSLT debugger, I can't get them to transform unless I comment out the XMLNS. This is both annoying and impractical, as I will be transforming thousands of documents and I would like to preserve the namespaces. oXygen uses Saxon 6.5.5 and Xalan transformation engines, and I am using XSL 1.0.
Does anyone have a solution? Also, the reason I'm asking now is because I'll be using Perl in the near future to do the job for me. If someone out there has experience with perl and XSLT and knows this NOT to be a problem, just as well. All the same, I'd love to have the answer because I'm a perfectionist! I just KNOW there is some <xsl:something> that will make it work, I just can't seem to find it. Here's some code for you:
XML:
Quote:
<?xml version="1.0" encoding="UTF-8"?>
<modsCollection xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-2.xsd">
<mods>
<titleInfo>
<title>[Series of letters of congratulation to Michael Tierney on his appointment as President of University College Dublin.
1947.]</title>
</titleInfo>
<name type="personal">
<namePart>Tierney, Michael, 1894-1975</namePart>
<role>
<roleTerm>fmo</roleTerm>
</role>
</name>
<name type="personal">
<namePart>Duignan, Michael</namePart>
<role>
<roleTerm>aut</roleTerm>
</role>
</name>
... etc
</mods>
</modsCollection>
Thanks in advance this could really help me out alot! My boss thanks you too, by proxy. Enough info in this post to correctly identify the shadowy Foomajick...
I don't know if you were after a different XSLT processor but I'd recommend using xsltproc (part of libxml - otherwise: http://www.xmlsoft.org/). It's a nice command-line utility and it works on your code without commenting out the namespaces (I checked).
Thanks for thi info. This would all be alot easier if I were on a better (than XP) system. I can't seem to get onto Igor Zlatovic's site which is supposed to have Win binaries. I've Cygwin installed so if anyone has a nice solution for installing into that, I'm up for it. Otherwise, it's ok because (as you can probably tell from the month that has passed) this isn't a real bottleneck or anything. We'll survive!
You may not need the last two, but I got them just in case.
Unzip them, put them anywhere you want. Then copy the contents of each /bin (inside each of the four packages) to a directory you have listed in your PATH environment variable. For me, that's my own homemade /bin directory, which I created so that I can pretend like I'm on a Linux system at work.
Then you can work away with your xslt transformations in the command line.
I found this about a thousand times quicker from the command line when processing large xml files.
Unfortunately, my first problem is not resolved! I got the same results, if I have an XMLNS in the code, it doesn't work. I'm beginning to suspect it might be the location of the XMLNS not being good. Will keep experimenting.
You can always go to the Saxon website and post a question,
make it clear with examples.
I've done this before and the Saxon maintainer himself
mailed me back a solution after a day or so.
I use a bit of XML and use saxon as standalone.
The advantage with saxon is it also includes an implementation
of Xquery.
I would prefer to use perl but haven't been able to find anything that does all saxon does. You get XSLT processors but I never found an xquery module.
Mind you I only had a dig on CPAN for an afternoon.
Edit:
oops, read further it says the XSLT part is version 6.5.5 ???
but saxon is 8.8, confused me. ???
Last edited by bigearsbilly; 10-19-2006 at 08:14 AM.
Well I've done some more experimenting, and to make it plainer, here's better code. The XML is validated with the XMLNS included. The stylesheet is complete, and XSLT 2.0. It's fairly straightforward.
XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-2.xsd" version="3.2">
<titleInfo>
<title>[Series of letters of congratulation to Michael Tierney on his appointment as President of University College Dublin. 1947.]</title>
</titleInfo>
<name type="personal">
<namePart>Tierney, Michael, 1894-1975</namePart>
<role>
<roleTerm>fmo</roleTerm>
</role>
</name>
<name type="personal">
<namePart>Duignan, Michael</namePart>
<role>
<roleTerm>aut</roleTerm>
</role>
</name>
</mods>
Now. It only outputs the values of the XML tags if I leave in the XMLNS in the <mods> element. That goes for oXygen AND xsltproc. (Using xsltproc, I've had to revert to XSLT 1.0 as well (just changed that one little number in the xslt from 2.0 to 1.0)). Perhaps the Windows version of xsltproc is dated?)
If I remove the xmlns info, it works in oXygen and through xsltproc, and produces a nice little html table.
Given that
1. The xmlns and subsequent xml are valid;
2. it breaks using the command line utility, and using oXygen (using Saxon 6.5.5 (xslt 1.0), Saxon8B (xslt2.0), and Xalan parsers)
and
3. it works without the xmlns in all of the above mentioned methods,
does this not sound like an XSLT problem, rather than a parser problem?
Thanks for the input so far, it's getting me going on it. I might try and post this to the StylusStudio forum where I've seen alot of XML discussion, even though I don't own a license!
Solution: XSLT transformation of XML document using XMLNS
Hi, I posted to the MODS listserve and the folks there had the answer. This is not specific to the MODS schema, it goes for any XML XSLT transformation involving namespaces, so hopefully others may find this helpful.
For your info:
Quote:
If the source XML contains namespace information (xmlns), associate the
namespace ('http://www.loc.gov/mods/v3') with the prefix 'mods' in the
XSLT template. Then prefix all mods elements called by the XSLT with
"mods:", for example:
<xsl:value-of match="mods:mods/mods:subject/mods:topic"/>
A perfect example is given in the first response below.
>associates the namespace ('http://www.loc.gov/mods/v3') with the
>prefix 'mods' you can use to reference elements in the namespace.
>I've always found it useful to start from a known working state, so I
>hope this gets you started.
>Good luck --
>Joe
>>Are you declaring the mods namespace and binding it to a prefix in the
>>stylesheet? E.g. you should have templates with xpaths like
>>"m:titleInfo" where the "m" prefix binds to the correct URI.
>>Bruce
>>>Here's a guess, though: you have xsl templates matching mods
elements, but the templates aren't name-spaced; e.g., you have
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.