<?xml version="1.0"?>
<xsl:stylesheet 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 version="1.0">

  <xsl:template match="prefiles">
    <files>
      <xsl:apply-templates/>
    </files>
  </xsl:template>

  <xsl:template match="list">
    <xsl:call-template name="process-list">
      <xsl:with-param name="values"><xsl:value-of select="@values"/>,</xsl:with-param>
      <xsl:with-param name="in" select="@in"/>
      <xsl:with-param name="param-prefix" select="@param-prefix"/>
      <xsl:with-param name="param-postfix" select="@param-postfix"/>
      <xsl:with-param name="out-prefix" select="@out-prefix"/>
      <xsl:with-param name="out-postfix" select="@out-postfix"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template name="process-list">
    <xsl:param name="values"/>
    <xsl:param name="in"/>
    <xsl:param name="param-prefix"/>
    <xsl:param name="param-postfix"/>
    <xsl:param name="out-prefix"/>
    <xsl:param name="out-postfix"/>

    <xsl:variable name="value" select="substring-before($values, ',')"/>

    <xsl:element name="file">
      <xsl:attribute name="param">
        <xsl:value-of select="$param-prefix"/>
        <xsl:value-of select="$value"/>
        <xsl:value-of select="$param-postfix"/>
      </xsl:attribute>
      <xsl:attribute name="in">
        <xsl:value-of select="$in"/>
      </xsl:attribute>
      <xsl:attribute name="out">
        <xsl:value-of select="$out-prefix"/>
        <xsl:value-of select="$value"/>
        <xsl:value-of select="$out-postfix"/>
      </xsl:attribute>
    </xsl:element>

    <xsl:if test="substring-after($values, ',')">
      <xsl:call-template name="process-list">
        <xsl:with-param name="values" select="substring-after($values, ',')"/>
        <xsl:with-param name="in" select="@in"/>
        <xsl:with-param name="param-prefix" select="@param-prefix"/>
        <xsl:with-param name="param-postfix" select="@param-postfix"/>
        <xsl:with-param name="out-prefix" select="@out-prefix"/>
        <xsl:with-param name="out-postfix" select="@out-postfix"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
