Julien
Julien

Reputation: 1158

Using XSLT, how to turn each tag into a div with a class matching the tag name?

Using XSLT, I'd like to be able to transform this :

<doc>
  <tag1>AAA</tag1>
  Hello !
  <tag2>BBB</tag2>
</doc>

into this :

<div class="doc">
  <div class="tag1">AAA</div>
  Hello !
  <div class="tag2">BBB</div>
</div>

...but without specifying explicitly any tag name in the stylesheet (there are too many in the real world)

What would be the best way to do this ?

Upvotes: 1

Views: 506

Answers (1)

Mario Menger
Mario Menger

Reputation: 5902

Something along the lines of

<xslt:template match="*">
    <div class="{local-name()}">
        <xsl:apply-templates />
    </div>
</xslt:template>

Upvotes: 6

Related Questions