如何更改xslt中的标签名称?
请问您可以告诉我如何更改标签名称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>
更新
您还可以使用轴更改标签,只有当具有特定的祖先 - 在你的情况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>
这里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版本的选择器
我们可以为某些特定http://xsltransform.net/bwdwsT/4 – user5711656
它改变所有' user5711656
我需要它只是改变''aa'标签里面没有'b' – user5711656
更新的链接http://xsltransform.net/bwdwsT/2 – user5711656