title: Network Mask to Shorthand in XSL
body: <p>I'm running into a bit of a pickle where I'm working out network masks into shorthand (ie. <code>255.255.255.0</code> = <code>/24</code>)</p>
  
  <p>I did a whole bunch of googling, and weirdly enough, no one has ever asked how to compute this in XSL.</p>
  
  <p>So I came up with my own solution: why not do a whole bunch of statements like:</p>
  
  <pre><code>&lt;xsl:choose&gt;
      &lt;xsl:when test="'255.255.255.0'"&gt;
          &lt;xsl:value-of select="'/24'"/&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:when test="'255.255.0.0'"&gt;
          &lt;xsl:value-of select="'/16'"/&gt;
      &lt;/xsl:when&gt;
      ...
  </code></pre>
  
  <p>and so on and so forth. Then I realized. I think I'm thinking too much outside the box. There has to be a solution to calculate this. There are too many possibilities of a network mask. Does anyone know how to calculate it?</p>