【问题标题】:Using XSLT, how to turn each tag into a div with a class matching the tag name?使用XSLT,如何将每个标签变成一个与标签名称匹配的类的div?
【发布时间】:2009-05-25 14:33:40
【问题描述】:

使用 XSLT,我希望能够对其进行转换:

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

进入这个:

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

...但没有在样式表中明确指定任何标签名称(现实世界中太多了)

最好的方法是什么?

【问题讨论】:

    标签: xslt class html


    【解决方案1】:

    类似的东西

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

    【讨论】:

    • 好久没做xsl的东西了,但是模板元素上的xslt前缀是故意的,还是应该是xsl?
    • 它可以是任何东西,具体取决于标题。它甚至可以是默认命名空间! &lt;template match="*"&gt;...
    • 确实像一个魅力,纠正了弗雷德里克所说的前缀。
    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多