桜、抹茶、白、日記

名古屋市在住のC++使いのcoderの日記だったもの。

MSDNのプロダクトキー一覧

わんくま同盟の中さんのブログにあった

[中の技術日誌] MSDN サブスクライバ ダウンロードのプロダクトキー用XSLT
http://naka.wankuma.com/site/column/internetexplorer/00002.htm
http://blogs.wankuma.com/shannon/archive/2008/06/24/145320.aspx

が最新のキー出力だとXMLのタグ名とか色々変わってしまって利用できないので、

[@IT] XSLTスタイルシート書き方講座
http://www.atmarkit.co.jp/fxml/tanpatsu/10xslt/xslt01.html

上記を見ながら適当に改修。

<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/>
  <xsl:template match="/">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head xmlns="http://www.w3.org/1999/xhtml">
        <title xmlns="http://www.w3.org/1999/xhtml">プロダクトキー一覧</title>
      </head>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="YourKey">
    <table border="1" summary="一覧" xmlns="http://www.w3.org/1999/xhtml">
      <colgroup span="2" xmlns="http://www.w3.org/1999/xhtml">
      </colgroup>
      <thead xmlns="http://www.w3.org/1999/xhtml">
        <tr xmlns="http://www.w3.org/1999/xhtml">
          <th xmlns="http://www.w3.org/1999/xhtml">Products</th>
          <th xmlns="http://www.w3.org/1999/xhtml">Key</th>
        </tr>
      </thead>
      <tbody xmlns="http://www.w3.org/1999/xhtml">
        <xsl:apply-templates />
      </tbody>
    </table>
  </xsl:template>

  <xsl:template match="Product_Key">
    <tr xmlns="http://www.w3.org/1999/xhtml">
      <td xmlns="http://www.w3.org/1999/xhtml">
        <xsl:value-of select="@Name" disable-output-escaping="no"/>
      </td>
      <td xmlns="http://www.w3.org/1999/xhtml">
        <xsl:for-each select="Key">
              <xsl:value-of select="." disable-output-escaping="no"/><br/>
        </xsl:for-each>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

まあ大きな変更点としては以下の部分だけですが。

<xsl:for-each select="Key">
  <xsl:value-of select="." disable-output-escaping="no"/><br/>
</xsl:for-each>

改修前のと同様にXMLファイルの頭に以下の2行を付ける。

<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="00002.xslt"?>

HTMLなんて真面目に書いた事ないのですが、まあちゃんと表示はされるので自分的には良しとする。
あ、何だか一週間振り位にプログラミングっぽいことした希ガス。まあ折角の16連休も毎日gdgdと過ごして、あっという間に半分以上過ぎてしまった訳ですが。