preceding軸

preceding軸

文書順でコンテキストノードより前に位置する全てのノードで、祖先ノード、属性ノード、名前空間ノード以外のノード。

preceding-sibling軸

コンテキストノードの兄弟ノードの中で,起点となるノードより文書順で前に位置するノード(兄に該当)。

(特記)position()関数の返す数値は、文書出現順でなくコンテキストノードに近いほうから1〜の数値が付く。

[サンプルXML文書を表示](下のフレームに)

XMLソース

<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet type="text/xsl" href="preceding01.xsl"?>
<root>
<title>preceding軸のテスト</title>
<祖父>祖父1</祖父>
<祖父>祖父2
<叔父>叔父1</叔父>
<叔父>叔父2</叔父>
<親>親
<兄>兄1</兄>
<兄>兄2</兄>
<私>私</私>
<弟>弟1</弟>
<弟>弟2</弟>
</親>
<叔父>叔父3</叔父>
<叔父>叔父4</叔父>
</祖父>
<祖父>祖父3</祖父>
<end>2005/4/13</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="/">
<xsl:apply-templates select="root/祖父/親/私"/>
</xsl:template>

<xsl:template match="私">
<xsl:for-each select="preceding::*">
<xsl:value-of select="."/>、
</xsl:for-each><br/>
<xsl:value-of select="preceding::*[position()=1]"/><br/>
<xsl:value-of select="preceding::*[position()=4]"/>
<hr/>
<xsl:for-each select="preceding-sibling::*">
<xsl:value-of select="."/>、
</xsl:for-each><br/>
<xsl:value-of select="preceding-sibling::*[position()=1]"/><br/>
<xsl:value-of select="preceding-sibling::*[position()=3]"/>・・・<br/>
<xsl:value-of select="preceding-sibling::兄[position()=2]"/><br/>
</xsl:template>
</xsl:stylesheet>

end(05/4/13)