xsl:namespace-aliasで置換されるのは名前空間のみか、接頭辞も含むのか。おそらくは名前空間のみだが、実装によっては接頭辞も置換するようだ。
例えば、勧告書内で挙げられている、次の例を考える。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> <xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> <xsl:template match="/"> <axsl:stylesheet> <xsl:apply-templates/> </axsl:stylesheet> </xsl:template> <xsl:template match="block"> <axsl:template match="{.}"> <fo:block><axsl:apply-templates/></fo:block> </axsl:template> </xsl:template> </xsl:stylesheet>
このスタイルシート(強調は石川による)を
<elements> <block>p</block> <block>h1</block> <block>h2</block> <block>h3</block> <block>h4</block> </elements>
に適応する。
このとき、axslを接頭辞に持つリテラル結果要素の名前空間URIがhttp://www.w3.org/1999/XSL/Transformに置換されるのは当たり前だが、果たしてaxslという接頭辞それ自身もxslに置換されるべきなのだろうか。
勧告を読む限りでは微妙に判断しづらく(接頭辞自体は展開名に関係ない)、実際XSLTプロセッサによって結果がまちまちな上、XSLTを解説しているページによっても解釈が異なる。手元で確認したところ。MSXSL4.0は接頭辞まで置換したが、Saxon6.5.3は名前空間URIのみを置き換えている。
<xsl:stylesheet xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="p"><fo:block><xsl:apply-templates /></fo:block></xsl:template>
<xsl:template match="h1"><fo:block><xsl:apply-templates /></fo:block></xsl:template>
<xsl:template match="h2"><fo:block><xsl:apply-templates /></fo:block></xsl:template>
<xsl:template match="h3"><fo:block><xsl:apply-templates /></fo:block></xsl:template>
<xsl:template match="h4"><fo:block><xsl:apply-templates /></fo:block></xsl:template>
</xsl:stylesheet>
<axsl:stylesheet xmlns:axsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<axsl:template match="p"><fo:block><axsl:apply-templates/></fo:block></axsl:template>
<axsl:template match="h1"><fo:block><axsl:apply-templates/></fo:block></axsl:template>
<axsl:template match="h2"><fo:block><axsl:apply-templates/></fo:block></axsl:template>
<axsl:template match="h3"><fo:block><axsl:apply-templates/></fo:block></axsl:template>
<axsl:template match="h4"><fo:block><axsl:apply-templates/></fo:block></axsl:template>
</axsl:stylesheet>
個人的には、コピーされるネームスペースノードの展開名まで考えるとSaxonの処理の方が好ましい気がする。
困ったときはMichael Kay氏に聞くのが1番ということで検索してみると関連した話題がメーリングリストで行われていた。kay氏が言うにはこの動作(接頭辞は置換しない)はXSLT1.0のルールに従ったものであり、XSLT2.0ではより明確に定義されているらしい。
さらに決定的なことにXalanのリリースノートによると、W3CのXSLワーキングループもこの動作を指示しているようだ。
Handling xsl:namespace-alias declarations: In release 2.0.D01, we reported the need to do some research concerning exactly how Xalan should handle xsl:namespace-alias declarations. As a result of discussions among members of the W3C Working Group on XSL, we have reached a more precise consensus on how namespaces should be represented when an xsl:namespace-alias declaration is in effect.
If a literal result element has a namespace prefix, the prefix will be preserved and the namespace URI of the element will be as specified in the xsl:namespace-alias element, but the result-prefix is not required to appear in the result. This also applies to the two other cases of "Literal namespace URI" mentioned in the XSLT Recommendation on Literal Result Elements. More simply, if the stylesheet calls for <axsl:foo> to be output as a literal result element, then it will be output as <axsl:foo> in the result, but the namespace associated with this "axsl" prefix will be as designated in the xsl:namespace-alias declaration.
強調は石川による。
以上よりMSXSLの実装はどちらかと言えば好ましくなく、XSLTによりXSL文章を出力する際に接頭辞をxslとしたいならば、リテラル結果要素の接頭辞をxslにするべきであり、勧告で例示されている接頭辞は全て逆転する必要があると言える。
って、真面目に調べて長文になっても、ついついこっちに書いてしまってArticlesが全く更新されないのはマズイ。
http://yudai.arielworks.com/memo/2004/10/15/150412.trackback
末尾に「2 + 5」の計算結果を繋げて下さい。例えば計算結果が「17」の場合、「150412.trackback17」です。これは機械的なトラックバックスパムを防止するための措置です。