title: Create xslt files programmatically
body: <p>I know that I can create <code>xml</code> files programmatically by using <code>DOM</code> <em>api</em> in java like the following:</p>
  
  <pre><code>DocumentBuilderFactory documentBuilderFactory = 
      DocumentBuilderFactory.newInstance();
  DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
  
  Document document = documentBuilder.newDocument();
  Element rootElement = document.createElement("map");
  document.appendChild(rootElement);
  
  Element em = document.createElement("string");
  em.setAttribute("name", "FirstName");
  ....
  </code></pre>
  
  <p>But are there any <em>API</em> 's to construct an <code>xslt</code> tree? (an api like Dom for example)</p>
  
  <p>I need somehing like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"&gt;
  &lt;xsl:template match="root"&gt;
  &lt;fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;
    &lt;fo:layout-master-set&gt;
      &lt;fo:simple-page-master master-name="my-page"&gt;
        &lt;fo:region-body margin="1in"/&gt;
      &lt;/fo:simple-page-master&gt;
    &lt;/fo:layout-master-set&gt;
  
    &lt;fo:page-sequence master-reference="my-page"&gt;
      &lt;fo:flow flow-name="xsl-region-body"&gt;
        &lt;fo:block&gt;
          &lt;fo:external-graphic width="100pt" height="100pt" content-width="50pt" content-height="50pt" src="images/shopping-cart_100.jpg"/&gt;
        &lt;/fo:block&gt;
        &lt;fo:block&gt;Good Morning, &lt;xsl:value-of select="name" /&gt;!&lt;/fo:block&gt;
        &lt;fo:block&gt;
          &lt;fo:table&gt;
               &lt;fo:table-body&gt;
                  &lt;fo:table-row&gt;
                      &lt;fo:table-cell border="solid 1px black" text-align="center" font-weight="bold"&gt;
                          &lt;fo:block&gt;
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>              &lt;xsl:for-each select="./friend"&gt;
                  &lt;fo:table-row&gt;
                  &lt;fo:table-cell border="solid 1px black" text-align="center"&gt;
                      &lt;fo:block&gt;
                          &lt;xsl:value-of select="position()" /&gt;
                      &lt;/fo:block&gt;
                  &lt;/fo:table-cell&gt;
                  &lt;fo:table-cell border="solid 1px black" text-align="center"&gt;
                      &lt;fo:block&gt;
                          &lt;xsl:value-of select="name" /&gt;
                      &lt;/fo:block&gt;
                  &lt;/fo:table-cell&gt;
                  &lt;fo:table-cell border="solid 1px black" text-align="center"&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>