Creating a Profile (Control File) via Script with XSLT

If you have a template and want to change a few things via script or command line, use an XSLT processor like sablot. For example, if you have an AutoYaST profile and want to fillout the hostname via script for any reason (if doing this so often, you want to script it)

First, create an XSL file

Example 3.1. Example file for replacing hostname/domain by script

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:y2="http://www.suse.com/1.0/yast2ns"
  xmlns:config="http://www.suse.com/1.0/configns"
  xmlns="http://www.suse.com/1.0/yast2ns"
  version="1.0">


  <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no" cdata-section-elements="source"/>

  <!-- the parameter names -->
  <xsl:param name="hostname"/>
  <xsl:param name="domain"/>

  <xsl:template match="/">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:template>

  <xsl:template match="y2:dns">
    <xsl:copy>
      <!-- where to copy the parameters -->
      <domain><xsl:value-of select="string($domain)"/></domain>
      <hostname><xsl:value-of select="string($hostname)"/></hostname>  
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>


  <xsl:template match="@*|node()" >
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

This file expects the "hostname" and the "domain" as parameters from the user.

<xsl:param name="hostname"/>
<xsl:param name="domain"/>

There will be a copy of those parameters in the dns section of the control file. That means, if there already is a domain element in the dns section, you will get a second one (no good).

If you want to create a new AutoYaST profile now from the template plus the XSL file, run the following command:

sabcmd add_hostname.xsl \$hostname=myHost \$domain=my.domain  template.xml

You will get a filled out AutoYaST profile then on STDOUT.

If you have multiple XSL files you want to apply to a template, do the following:

sabcmd add_hd_vg.xsl \$device=/dev/sda \$partition=p2 \$vg=system \
        | sabcmd add_harddisk.xsl \$device=/dev/system \$lvm=true \
        | sabcmd ....
        | sabcmd add_hostname.xsl \$hostname=myHost \$domain=my.domain

Pipe the output of each sabcmd to the next sabcmd.

For more information about XSLT, go to the official Web page www.w3.org/TR/xslt