Tiago Neto
Tiago Neto

Reputation: 379

XSLT apply a template with a condition in the path

I'm quite new to XSLT so I'm trying to apply a specific template (header-component) and then load all of them except the header-template.

    <html>
  <head>
    <title>My page</title>
  </head>
  <body>
    <div class="header">
       <xsl:apply-templates select="page-components/header-component"/>
    </div>
    <div>
      <xsl:apply-templates select="page-components/*"/>  
    </div>
  </body>
</html>

With my solution the header-component is being loaded twice (as obvious).

Upvotes: 0

Views: 520

Answers (1)

fafl
fafl

Reputation: 7385

Instead of writing

<xsl:apply-templates select="page-components/*"/>

just write

<xsl:apply-templates select="page-components/*[not(name()='header-component')]"/>

to exclude the element you already processed.

Upvotes: 1

Related Questions