■ワイルドカード(*)
・child::* の省略表記で、ロケーションステップ(Location Step)のノードテスト(node test)部分に使う。
・(軸がattributeの場合)全ての属性ノードを
(軸がnamespaceの場合)全ての名前空間ノードを
(軸が上記以外)直下の全子要素ノード(孫要素以下は含まない。孫以下も含む全要素は"//*"で)
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet type="text/xsl" href="xpath21.xsl"?>
<root>
<title>わたしの家系</title>
<叔父>叔父さん
<従姉妹>叔父さんの娘</従姉妹>
</叔父>
<親 年齢="88">お父さんお母さん
<!--私の兄弟姉妹です-->
<姉 年齢="62">お姉さん
<おい>お姉さんの息子<孫>姉の息子の娘</孫></おい>
</姉>
<私 年齢="58">おいら
<長男 年齢="38">長男<孫>長男の娘</孫></長男>
<長女>長女<孫>長女の息子</孫></長女>
<次男>次男</次男>
</私>
<弟 年齢="54">弟
<めい>弟の娘</めい>
</弟>
<妹 年齢="48">妹</妹>
</親>
<叔母>叔母さん
<従兄弟>叔母さんの息子</従兄弟>
</叔母>
<end>以上です(2004/5/12)</end>
</root>
XSLソース
<?xml version="1.0" encoding="Shift_Jis"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS"/>
<xsl:template match="/">
<center><H3>XPath:ワイルドカード(*)のいろいろな使用例</H3></center>
「/*」は・・・→<xsl:apply-templates select="/*"/>
<hr/>
「root/*」は・・・→<xsl:apply-templates select="root/*"/>
<hr/>
「root//*」は・・・→<xsl:apply-templates select="root//*"/>
<hr/>
「root/親/私/*」は・・・→<xsl:apply-templates select="root/親/私/*"/>
<hr/>
「root/親//*」は・・・→<xsl:apply-templates select="root/親//*"/>
<hr/>
「root/親/*/*/孫」は・・・→<xsl:apply-templates select="root/親/*/*/孫"/>
<hr/>
「root/親//@*」は・・・→<xsl:apply-templates select="root/親//@*"/>
<hr/>
「root//*[@年齢]」は・・・→<xsl:apply-templates select="root//*[@年齢]"/>
</xsl:template>
<xsl:template match="/*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root/*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root//*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root/親/私/*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root/親//*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root/親/*/*/孫">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root/親//@*">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
<xsl:template match="root//*[@年齢]">
<xsl:value-of select="position()" /><xsl:value-of select="name()" />、
</xsl:template>
</xsl:stylesheet>
end(04/5/12)