XSLTのデバッグ

もう前の2014年の3月の投稿ですが、XSL-Listに次のように題された話題が載っています.

Managing debug logging in complex transforms: what do people do?

話の発端はEliot Kimberさんです.自分はXSLTインタラクティブデバッグはあまり役にたたないと思う.デバッグメッセージを出してやっているが、もっとうまい方法はないか?という問いかけです.

このスレッドを全部読むと世界の様々な開発者がいろんな形でXSLTデバッグに取り組んでいる様子がわかって大変興味深いです.

1.oXygenなんかのインタラクティブデバッグ環境でやるという人
2.それはとても無理であるとデバッグメッセージを出してやっているという人

そしてXSLT 3.0ではもっとうまくデバッグできるようになれないか?という話もあります.

私はどのようにデバッグしているかといいますとほとんどコンソールデバッグです.かつて会社の中でXSLTの開発をやっている人に聞いたところみんなインタラクティブデバッグをやっていると聞いてびっくりしたことがあります.

わたしがインタラクティブデバッグをやらないのは、たいていの場合において次のGraydonさんのお話と同じ破目になっているからです.


>> That's interesting... I use oXygen daily and get on well with its
>> debugger - the click back feature (where you click on a node in the
>> result and it highlights the line in the xslt and context node in the
>> source xml that created it) is a killer feature (I don't know if it's
>> common or unique to oxygen).  Equally, putting break points in the
>> xslt and then clicking around the call stack to see how you got there
>> can be a quick way of diagnosing issues.

>That is all true and it's wonderful when it's practically available.

>My experience is that it simply takes too long to be useful with "real"
>(that is, the multi-thousand-template, here's a several tens of MB of
>input document, horrid conversion stylesheets I was most recently
>dealing with) input.  Two orders of magnitude slower than non-debug
>execution, and a definitive answer to "but where did it die?" could be
>had by other, if more effortful, means.

山ほどのテンプレートがあり、巨大な変換元XMLファイルがありという状況では、とてもインタラクティブデバッグでは追いつかないのです.そしてどこのどのデータが原因でおかしくなっているかは、時としてSaxonの-Tオプションをつけてコールトレースをやらないとわかりません.そしてコールトレースを出すと、oXygenからのバッチ実行ですらも時としてメモリー不足で落ちます.このようなときは最後の手段でSaxonをバッチファイルで起動してトレースを出して追わねばなりません.

自分としては特にインタラクティブデバッグを否定しているつもりはないのですが、差し迫ったときはたいていコールトレースやコンソールデバッグしか手段がないのです.

話に出ていたXSLT 3.0ではxsl:assertと静的変数を使用できるuse-when属性がデバッグに有用です.


There are two things in XSLT 3.0 designed to make this easier:
xsl:assert, and static variables/parameters

xsl:assert is like xsl:message wrapped in an xsl;If.

Static variables can be used in conjunction with xsl:use-when effectively
as an "ifdef", that is a compile-time conditional. So rather than
commenting code out, you tag it with use-when="$DEBUG".

xs:assertはxsl:message + xsl:ifですが、use-when属性にstatic variableを指定できるようになるというのは便利です.
これらはいずれ紹介したいと思います.