1

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 ?

0

1 Answer 1

6

Something along the lines of

<xslt:template match="*">
    <div class="{local-name()}">
        <xsl:apply-templates />
    </div>
</xslt:template>
3
  • I haven't been doing xsl stuff in quite a while, but is the xslt prefix on the template element deliberate, or should it be xsl? Commented May 25, 2009 at 14:48
  • It can be anything, depending on the header. It can even be a default namespace! <template match="*">...
    – alamar
    Commented May 25, 2009 at 14:57
  • Works like a charm indeed, correcting the prefix as Fredrik said.
    – Julien
    Commented May 25, 2009 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.