First a little context: I use a collection management software, GCStar, to manage my digital library (comics/manga/films, you name it – it’s pretty awesome except for books). Problem is, it doesn’t let me sort the shelf by multiple keys, say by Series AND Episode number. Episodes added later will always show up lower in the shelf, grouped by Series.
I pattered around the configurations and found that the .gcs file it uses is nothing but an XML (which I am only cursorily familiar with). Goes like this:
<?xml version="1.0" encoding="UTF-8"?>
<collection type="GCTVepisodes" items="101" version="1.6.1">
<information>
<maxId>101</maxId>
</information>
<item
id="1"
name="The Vice President Doesn't Say Anything about the Possibility of
Him Being the Main Character"
series="Baccano"
season="1"
episode="1"
...
>
<synopsis>It's 1931 and...</synopsis>
...
</item>
<item ...
The program, far as I understand, will always order descending by ID (which increases whenever I add an episode). So I need a transform on this which will:
- Sort the XML by series, then season, then episode
- Change the id attributes accordingly, starting from 1 to end (also reset maxId based on that)
- Write it all out into identical format to another XML.
How to do this (not talking about cut-pasting code here, obviously)? Can XSLT do all this stuff? Should I look into a tree-based parser in Perl? This is the weekend and I’m on a Linux machine, so open-source solutions running on UNIX would be nice – something in Perl would probably be best. What should I read up on?
If I can’t do this at home, well, I can always design a small datastage job at the office, but I’d seriously like a simpler solution.
Thanks! 🙂
The maxId (and items in collection) value should not change, because you are not removing or adding ids.
If you want an easy commandline open-source XSLT transformator use XSLTProc from libxml2/libxslt. It is available on nearly every standard linux. http://xmlsoft.org/XSLT/xsltproc2.html
Use this command
xsltproc transform.xsl input.xml >output.xmlAnd here is a solution, the XSLT transform stylesheet, that should work 😉 (I had enough free time to code it)
I used this simplified data to test it:
And this is the result (look at how the position and id changed):