2017-02-28 69 views
0

請問您可以告訴我如何更改標籤名稱xslt? ?我想將img標記更改爲imp-img標記。 這裏是我的代碼 http://xsltransform.net/bwdwsT/1如何更改xslt中的標籤名稱?

進出料

<!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

+0

更新的鏈接http://xsltransform.net/bwdwsT/2 – user5711656

回答

0

您還可以使用軸更改標籤,只有當具有特定的祖先 - 在你的情況aa。剛剛在選擇使用ancestor::aa

<?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> 
0

這裏http://xsltransform.net/bwdwsT/5

<?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="aa/div/div/p/imp-img">   
     <img><xsl:apply-templates select="@*|node()" /></img> 
    </xsl:template> 


</xsl:transform> 

它在此基礎上How do I rename XML tags using XSLT

更新1

氖w版本的選擇器

+0

我們可以爲某些特定http://xsltransform.net/bwdwsT/4 – user5711656

+0

它改變所有'<做到這一點imp-img'到img – user5711656

+0

我需要它只是改變''aa'標籤裏面沒有'b' – user5711656