<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/xml.xsl" type="text/xsl"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title>nulog, NULL::something : out of the headphone &gt; 2005 &gt; July &gt; 03 &gt; リハビリと ruby-xslt</title>
  <link href="http://lowreal.net/logs/2005/07/03/1"/>
  <icon>http://lowreal.net/img/banner.png</icon>
  <link rel="self" type="application/atom+xml" href="http://lowreal.net/logs/2005/07/03/1.atom"/>
  <link rel="alternate" type="application/xhtml+xml" href="http://lowreal.net/logs/2005/07/03/1.xhtml"/>
  <updated>2005-07-03T01:47:08+09:00</updated>
  <author>
    <name>cho45(砂糖)</name>
  </author>
  <id>http://lowreal.net/2005/07/03/1</id>
  <entry>
    <title>リハビリと ruby-xslt</title>
    <link rel="alternate" type="text/html" href="http://lowreal.net/logs/2005/07/03/1.html"/>
    <link rel="alternate" type="application/xml+xhtml" href="http://lowreal.net/logs/2005/07/03/1.xhtml"/>
    <updated>2005-07-03T01:47:08+09:00</updated>
    <published>2005-07-03T01:47:08+09:00</published>
    <id>http://lowreal.net/2005/07/03/1</id>
    <category term="web"/>
    <category term="xml"/>
    <category term="xslt"/>
    <content type="xhtml" xml:base="http://lowreal.net/">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>ruby-xslt 使うと <abbr title="XSL Transformations">XSLT</abbr> から Ruby のメソッドを呼べるみたいなので、とても使ってみたい。（何をするか、はともかく）</p>
        <p>ただ、ちょっと実装が残念な形。</p>
        <blockquote title="test_function.rb">
          <pre class="Ruby">
class XML::XSLT
    def round_trip( arg )
        arg
    end
    def type( arg )
        arg.class.to_s
    end
end

xslt = XML::XSLT.new()
xslt.xsl = "functions.xsl"
xslt.xml = "test.xml"
xslt.extFunction("roundTrip", "http://test.none", xslt, "round_trip")
xslt.extFunction("type", "http://test.none", xslt, "type")
</pre>
        </blockquote>
        <p>俺としては Proc オブジェクトとか、ブロックを直接渡したい。すなわち次のように</p>
        <pre class="Ruby">
xslt.extFunction("roundTrip", "http://test.none/", xslt) do |arg|
    arg
end
#または
round_trip = lambda {|arg| arg}
xslt.extFunction("roundTrip", "http://test.none", xslt, round_trip)

# あるいはまとめたクラス / インスタンスを登録する形。
# もとのヤツに似ているけど名前が衝突しない。
class XSLTFunctions
    def round_trip(arg)
        arg
    end

    def type(arg)
       arg.class.to_s
    end
end

xslt.set_ext_functions("http://test.none", XSLTFunctions) # XSLTFunctions.new
# この場合 XSLT から呼ぶ関数名は Ruby でのメソッド名と同じになる。とか。

# やはり Ruby は書いていて気持ちいい。
</pre>
        <p>ちょっとどうでもいいけど、なんかこの <abbr>PC</abbr> 描画がおかしい。温度のせい?</p>
        <ins datetime="2005-07-03T01:56:53+09:00">
          <p>再起動したらなおった？ ちょっと時間おかないと分からない。</p>
          <p>限りなく不安定な <abbr>PC</abbr> だ。グラフィックボードにもファンがついているから、グラフィックボードが暑くて困っているのかもしれない。しかしゲームのとき気にならない (or 症状が出ていない？) のはなぜだろう。最も影響うけやすそうなんだけど。</p>
        </ins>
      </div>
    </content>
  </entry>
</feed>
