Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:17:49+00:00 2026-05-23T16:17:49+00:00

First a little context: I use a collection management software, GCStar, to manage my

  • 0

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:

  1. Sort the XML by series, then season, then episode
  2. Change the id attributes accordingly, starting from 1 to end (also reset maxId based on that)
  3. 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! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:17:49+00:00Added an answer on May 23, 2026 at 4:17 pm

    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.xml

    And here is a solution, the XSLT transform stylesheet, that should work 😉 (I had enough free time to code it)

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    
    <xsl:strip-space elements="*"/>
    
    <!-- Default: copy everything -->
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    
    <!-- remove items, they will be sorted and inserted later -->
    <xsl:template match="/collection/item"/>
    
    <!-- remove id -->
    <xsl:template match="/collection/item/@id"/>
    
    <xsl:template match="/collection">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
            <!-- copy and sort item by series, then season, then episode -->
            <xsl:for-each select="item">
                <xsl:sort select="@series" data-type="text"/>
                <xsl:sort select="@season" data-type="number"/>
                <xsl:sort select="@episode" data-type="number"/>
                <xsl:copy>
                    <xsl:attribute name="id">
                        <xsl:value-of select="position()"/>
                    </xsl:attribute>
                    <!-- copy the rest of item -->
                    <xsl:apply-templates select="@*|node()"/>
                </xsl:copy>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
    
    </xsl:stylesheet>
    

    I used this simplified data to test it:

    <?xml version="1.0" encoding="UTF-8"?>
    <collection type="GCTVepisodes" items="5" version="1.6.1">
     <information>
      <maxId>5</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"/>
    
     <item
      id="2"
      name="blabla"
      series="c"
      season="1"
      episode="2"/>
    
     <item
      id="3"
      name="abc"
      series="Baccano"
      season="2"
      episode="1"/>  
    
     <item
      id="4"
      name="blabla2"
      series="Baccano"
      season="1"
      episode="2"/>
    
     <item
      id="5"
      name="first of c"
      series="c"
      season="1"
      episode="1"/>
    
    </collection>
    

    And this is the result (look at how the position and id changed):

    <?xml version="1.0" encoding="UTF-8"?>
    <collection type="GCTVepisodes" items="5" version="1.6.1">
      <information>
        <maxId>5</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"/>
      <item id="2" name="blabla2" series="Baccano" season="1" episode="2"/>
      <item id="3" name="abc" series="Baccano" season="2" episode="1"/>
      <item id="4" name="first of c" series="c" season="1" episode="1"/>
      <item id="5" name="blabla" series="c" season="1" episode="2"/>
    </collection>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To first give a little bit of context, my use-case is that my partner
A little background first: I'm a designer/developer and decided to use subversion for a
First, a little bit of context to explain why I am on the UDP
I have first to explain a little bit my context, then the question: I
First, a little background. I have a DataContext object (Linq to SQL). I use
A little context first: I would say I have good SQL server experience, but
Visual Studio 2010 Express, Windows Forms. Have made myself my first little application which
First a little background: I have already managed to connect to a Microsoft SOAP
A little background first. I've been tasked with encrypting files with a Powershell script
First, a little background, because there is a lot of interaction going on: I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.