3 <xsl:stylesheet version="1.0"
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
6 xmlns:node="http://xsltsl.org/node"
7 extension-element-prefixes="doc node">
9 <doc:reference xmlns="">
11 <releaseinfo role="meta">
12 $Id: node.xsl 3991 2004-11-10 06:51:55Z balls $
15 <surname>Ball</surname>
16 <firstname>Steve</firstname>
20 <holder>Steve Ball</holder>
24 <title>Node Templates</title>
28 <title>Introduction</title>
30 <para>This stylesheet module provides functions for reporting on or manipulating nodes and nodesets.</para>
37 <doc:template name="node:xpath" xmlns="">
38 <refpurpose>Returns an XPath location path</refpurpose>
41 <para>This template returns an XPath location path that uniquely identifies the given node within the document.</para>
49 <para>The node to create an XPath for. If this parameter is given as a nodeset, then the first node in the nodeset is used.</para>
56 <para>Returns an XPath location path as a string.</para>
60 <xsl:template name="node:xpath">
61 <xsl:param name="node" select="."/>
65 <xsl:when test="$node">
67 <xsl:for-each select="$node[1]/ancestor-or-self::*">
68 <xsl:text/>/<xsl:value-of select="name()"/>
69 <xsl:text/>[<xsl:value-of select="count(preceding-sibling::*[name() = name(current())]) + 1"/>]<xsl:text/>
74 <xsl:when test="$node[1]/self::comment()">
75 <xsl:text>/comment()</xsl:text>
76 <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::comment()) + 1" />]<xsl:text/>
79 <xsl:when test="$node[1]/self::processing-instruction()">
80 <xsl:text>/processing-instruction()</xsl:text>
81 <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::processing-instruction()) + 1" />]<xsl:text/>
84 <xsl:when test="$node[1]/self::text()">
85 <xsl:text>/text()</xsl:text>
86 <xsl:text/>[<xsl:value-of select="count($node[1]/preceding-sibling::text()) + 1" />]<xsl:text/>
89 <xsl:when test="not($node[1]/..)">
90 <xsl:text>/</xsl:text>
93 <xsl:when test="count($node[1]/../namespace::* | $node[1]) = count($node[1]/../namespace::*)">
94 <xsl:text/>/namespace::<xsl:value-of select="name($node[1])" />
97 <xsl:when test="count($node[1]/../@* | $node[1]) = count($node[1]/../@*)">
98 <xsl:text/>/@<xsl:value-of select="name($node[1])" />
105 <xsl:text>/..</xsl:text>
112 <doc:template name="node:type" xmlns="">
113 <refpurpose>Return node type</refpurpose>
116 <para>Returns the type of a node as a string.</para>
124 <para>The node to get the type for. If this parameter is given as a nodeset, then the first node in the nodeset is used.</para>
131 <para>Returns node type as a string. Values returned are:</para>
136 <para><literal>element</literal></para>
140 <term>Text Node</term>
142 <para><literal>text</literal></para>
148 <para><literal>comment</literal></para>
152 <term>Processing Instruction</term>
154 <para><literal>processing instruction</literal></para>
161 <xsl:template name="node:type">
162 <xsl:param name="node" select="."/>
165 <xsl:when test="not($node)"/>
166 <xsl:when test="$node[1]/self::*">
167 <xsl:text>element</xsl:text>
169 <xsl:when test="$node[1]/self::text()">
170 <xsl:text>text</xsl:text>
172 <xsl:when test="$node[1]/self::comment()">
173 <xsl:text>comment</xsl:text>
175 <xsl:when test="$node[1]/self::processing-instruction()">
176 <xsl:text>processing instruction</xsl:text>
178 <xsl:when test="not($node[1]/parent::*)">
179 <xsl:text>root</xsl:text>
181 <xsl:when test="count($node[1] | $node[1]/../namespace::*) = count($node[1]/../namespace::*)">
182 <xsl:text>namespace</xsl:text>
184 <xsl:when test="count($node[1] | $node[1]/../@*) = count($node[1]/../@*)">
185 <xsl:text>attribute</xsl:text>
190 <doc:template name="node:copy" xmlns="">
191 <refpurpose>Copy Nodes</refpurpose>
194 <para>Makes a copy of the given nodes, including attributes and descendants.</para>
202 <para>The nodes to copy.</para>
209 <para>Returns the copied nodes as a result tree fragment.</para>
213 <xsl:template name='node:copy'>
214 <xsl:param name='nodes' select='.'/>
216 <xsl:for-each select='$nodes'>
218 <xsl:for-each select='@*'>
222 <xsl:for-each select='node()'>
223 <xsl:call-template name='node:copy'/>