如何在xslt中更改标签名称? [英] how to change the tag name in xslt?

查看:110
本文介绍了如何在xslt中更改标签名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您告诉我如何更改标签名称xslt?我想将img标记更改为imp-img标记. 这是我的代码 http://xsltransform.net/bwdwsT/1

could you please tell me how to change the tag name xslt ? ?I want to changeimg tag to imp-img tag . here is my code http://xsltransform.net/bwdwsT/1

预期

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<hmtl>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>New Version!</title>
   </head>
   <aa>
            <div class="section1">
         <div class="Normal">
            <p>
               <imp-img height="260" alt="" hspace="6" width="310" align="left" vspace="6" src="/photo/a.cms">
               ffff<br>
               <br>
               hh<br>
               <br>
               vvggg<br>
               <br>
               vv<br>
               <br>
               ftr<br>
               <br>
               fff
            </p>

         </div>

      </div>

   </aa>
</hmtl>

`转换代码

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />

    <xsl:template match="/">
      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
        <xsl:apply-templates/>
      </hmtl>
    </xsl:template>

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:transform>

当前输出

<!DOCTYPE html
  PUBLIC "XSLT-compat">
<hmtl>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>New Version!</title>
   </head>
   <aa>

      <div class="section1">

         <div class="Normal">

            <p>
               <span class="Drop-Film" multiline="0">
                  <span class="italic" multiline="0">
                     \xxxcc
                     </span>
                  </span>

            </p>

            <p>
               xxx
            </p>

            <p>
               xxxx
            </p>

         </div>

      </div>

   </aa>
</hmtl>

已更新

http://xsltransform.net/bwdwsT/2

推荐答案

您还可以仅在具有特定祖先的情况下使用axis来更改标签-在您的情况下为aa.只需在选择器中使用ancestor::aa

You can also use axis to change tag only when has specific ancestor - in your case aa. Just use ancestor::aa in the selector

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <hmtl>
            <head>
                <title>New Version!</title>
            </head>
            <xsl:apply-templates/>
        </hmtl>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="imp-img[ancestor::aa]">
        <img>
            <xsl:apply-templates select="@*|node()"/>
        </img>
    </xsl:template>
</xsl:transform>

这篇关于如何在xslt中更改标签名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆