title: Creating attribute nodes from HTML style attribute value by XSL
body: <p>I'm trying to change a XML document into xsl:fo by using xslt. In some element nodes of the XML there is HTML style attribute like attribute node, and I want to change its value into separated attribute nodes</p>
  
  <p>sample of XML is...</p>
  
  <pre><code>&lt;books&gt;
      &lt;book&gt;
          &lt;price style="mycolor:red;myvalign:center;"&gt;10&lt;/price&gt;
      &lt;/book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>and I want to change it like this</p>
  
  <pre><code>&lt;books&gt;
      &lt;book&gt;
          &lt;price mycolor="red" myvalign="center"&gt;10&lt;/price&gt;
      &lt;/book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>I can tokenize the value of 'style' attribute node (got help from stackoverflow here) and rendering it as key-value paired but I don't know how can I set these key-value pair as attribute of node of calling template.</p>
  
  <p>Below is a xslt I tried, but has error. Could you help me please?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="1.0"&gt;
  
      &lt;xsl:template match="books"&gt;
          &lt;xsl:element name="books"&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/xsl:element&gt;
  
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="book"&gt;
          &lt;xsl:element name="book"&gt;
              &lt;xsl:apply-templates /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="price"&gt;
          &lt;xsl:variable name="style" select="./@style" /&gt;
  
          &lt;xsl:variable name="result"&gt;
              &lt;xsl:call-template name="tokenize"&gt;
                  &lt;xsl:with-param name="style" select="$style" /&gt;
              &lt;/xsl:call-template&gt;
          &lt;/xsl:variable&gt;
  
          &lt;xsl:element name="price"&gt;
              &lt;xsl:value-of select="$result"/&gt;
              &lt;xsl:value-of select="."/&gt;  
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="tokenize"&gt;
          &lt;xsl:param name="style" /&gt;
          &lt;xsl:variable name="styleFrag" select="substring-before($style, ';')" /&gt;
          &lt;xsl:if test="$styleFrag"&gt;
              &lt;xsl:variable name="styleKey" select="substring-before($styleFrag, ':')" /&gt;
              &lt;xsl:variable name="styleVal" select="substring-after($styleFrag, ':')" /&gt;
              &lt;xsl:variable name="concat1"&gt;&amp;lt;xsl:attribute name=&amp;apos;&lt;/xsl:variable&gt;
              &lt;xsl:variable name="concat2"&gt;&amp;apos;&amp;gt;&amp;lt;xsl:value-of select=&amp;apos;&lt;/xsl:variable&gt;
              &lt;xsl:variable name="concat3"&gt;&amp;apos; /&amp;gt;&amp;lt;/xsl:attribute&amp;gt;&lt;/xsl:variable&gt;
              &lt;xsl:variable name="concatted" select="concat($concat1, $styleKey, $concat2, $styleVal, $concat3)" /&gt;
              &lt;xsl:value-of select="$concatted" /&gt;
              &lt;xsl:call-template name="tokenize"&gt; 
                  &lt;xsl:with-param name="style" select="substring-after($style,';')" /&gt; 
              &lt;/xsl:call-template&gt;
          &lt;/xsl:if&gt;  
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Thank you. </p>