XML and XSLT

The AKS format is simply a zipped XML file (note that non-zipped XMLs work too). The XSD of the AKS format can be found at the root of the AT2 package.

Why XML some might ask?

Simply because this is a standard exchange format that is:

  • human-readable (most of the time)
  • quite easy to parse
  • easy to generate

Its only real inconvenience is its verbosity.

But there is one more advantage: thanks to a language like XSLT, it is possible to transform a song. With a script, one can, for example:

  • modify notes
  • generate new notes
  • mix songs into one
  • etc.

Don’t hesitate to send me XSLT scripts, which can be published here for anyone to use!

Example: swap track notes

This example was kindly provided by Cpcitor. It swaps the middle (channel 2) and right (channel 3) notes.

Use:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:aks="http://www.julien-nevo.com/ArkosTrackerSong" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">
  <xsl:output method="xml" encoding="utf-8" indent="yes"/>
  <xsl:preserve-space elements="*"/>
  <!--Base template implementing XML identity function.-->
  <xsl:template match="@*|*|processing-instruction()|comment()|node()">
    <xsl:copy>
      <xsl:apply-templates select="*|@*|text()|processing-instruction()|comment()|node()"/>
    </xsl:copy>
  </xsl:template>
  <!--Swap middle (2) and right (3) tracks. Should work even with AKS files that have more than 1 PSG. -->
  <xsl:template match="aks:pattern">
    <xsl:copy>
      <xsl:apply-templates select="aks:height"/>
      <xsl:apply-templates select="aks:speedTrackNumber"/>
      <xsl:apply-templates select="aks:eventTrackNumber"/>
      <xsl:apply-templatesselect="aks:patternCell[1>=position()]"/>
      <xsl:apply-templatesselect="aks:patternCell[3]"/>
      <xsl:apply-templatesselect="aks:patternCell[2]"/>
      <xsl:apply-templatesselect="aks:patternCell[position()>=4]"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Use:

xsltproc -o <output.aks> <script above.xsl> <input song.aks>