I want to process nodes with apply-templates but use different modes to match the right template-rules for all the nodes within the sequence.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<story>
<p class="h1">
<content>heading</content>
<br/>
</p>
<p>
<content>some text</content>
<br/>
<content>more text...</content>
</p>
</story>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:element name="div">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="p">
<xsl:choose>
<xsl:when test="@class='h1'">
<xsl:element name="h1">
<!--apply-tempaltes mode:#default, for br mode:ignore-->
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="p">
<!--apply-tempaltes mode:#default-->
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="content" mode="#default">
<xsl:element name="span">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="br" mode="#default">
<xsl:element name="br"/>
</xsl:template>
<xsl:template match="br" mode="ignore"/>
</xsl:stylesheet>
Wanted Output:
<?xml version="1.0" encoding="UTF-8"?>
<story>
<h1 class="h1"><span>heading</span>
</h1>
<p><span>some text</span>
<br/>
<span>more text...</span>
</p>
</story>
XSLT-version is 2.0. I know, there are other ways to achieve the wanted output for this example, but i would like to use the mode-attributes.
#defaultwill will not work, as soon as i use modeignore. i could go withmode="#all"for templatematch="content". I'm sure, there is a better solution. - FelHabrelements if they are inside ap[@class = 'h1']element? - Mathias Müller<xsl:apply-templates/>with different modes, depending on their names. Yes, i want to ignorebrelements but without using predicates in the match-pattern. - FelHaxsl:apply-templates, e.g.<xsl:apply-templates select="node() except br"/>,<xsl:apply-templates select="br" mode="mode-name"/>, only as you want to ignore the element you don't need the second apply-templates at all, applying only tonode() except brsuffices. - Martin Honnen