In the code bellow I'm applying all the templates to the element chapter (in the end of the code) but I would like to know how it is possible to apply all the templates to this element except a spefic one. In this case it's the element title because I'm already selecting it in the line before and it appears repeated in the html file. Someone?
<xsl:template match="chapter">
<h3>
<a name="{@id}"><xsl:value-of select="title"/></a>
</h3>
<xsl:apply-templates/>
</xsl:template>
Output:
<h3>Title</h3>
Title<br>
Text.
The <xsl:apply-templates> element selects a set of nodes in the input tree and instructs the processor to apply the proper templates to them.
With <xsl:apply-templates> the current node moves on with every iteration, whereas <xsl:call-template> does not change the current node.
If you need to select all but a specific attribute, use local-name( ) . The self axis, when applied to a name, refers only to elements. In other words, use <xsl:copy-of select=@*[local-name( ) != 'ignored-attribute']/> and not <xsl:copy-of select=@*[not(self::ignored-attribute)]/> .
The match attribute is used to associate a template with an XML element. The match attribute can also be used to define a template for the entire XML document. The value of the match attribute is an XPath expression (i.e. match="/" defines the whole document).
A plain <xsl:apply-templates/>
is equivalent to <xsl:apply-templates select="node()" />
, i.e. all child nodes. You can exclude certain nodes by using the XPath 2.0 except
operator, e.g.
<xsl:apply-templates select="node() except title" />
This would select all child nodes except those that are elements with the name title
. If you are only interested in child elements (not text nodes etc.) then you could use * except title
instead.
The except
operator essentially implements set difference - you're not limited to simple element names on the right, you can use any expression that returns a sequence of nodes, e.g.
node() except (title | div[@class = 'heading'])
X except Y
selects all nodes that are in the sequence selected by X
and not also in the sequence selected by Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With