How do I use XSLT, how do I turn each tag into a div with a class matching the tag name?

Using XSLT, I would like to be able to transform this:

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

      

in it:

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

      

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

What would be the best way to do this?

+1


a source to share


1 answer


Something along the lines



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

      

+6


a source







All Articles