Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 将属性移动到父级_Xslt - Fatal编程技术网

Xslt 将属性移动到父级

Xslt 将属性移动到父级,xslt,Xslt,我正在尝试使用XSLT重新构造一些HTML。我如何才能将其转换为: <div> <h2 class="foo">...</h2> <p>bar</p> </div> ... 酒吧 进入: ... 酒吧 如果您使用的是XSLT 1.0,则以下XSLT <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Tran

我正在尝试使用XSLT重新构造一些HTML。我如何才能将其转换为:

<div>
    <h2 class="foo">...</h2>
    <p>bar</p>
</div>

...
酒吧

进入:


...
酒吧


如果您使用的是XSLT 1.0,则以下XSLT

<xsl:stylesheet version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*"/>
  <xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="div">
   <xsl:copy>
      <xsl:attribute name="class">
        <xsl:value-of select="h2/@class"/>
      </xsl:attribute> 
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="h2/@class"/>
</xsl:stylesheet>
如果您使用的是XSLT2.0,则可以将其调整为

<xsl:attribute name="class" select="h2/@class"/>


您的意图很清楚,但前面的评论是对的-您忘记显示当前的XSLT代码,或者告诉我们哪些代码不起作用。@PhilVallone:我尝试了一些不同的方法,但我真的在黑暗中蹒跚而行。我将检查下面的答案-谢谢。
<div class="foo">
 <h2>...</h2>
 <p>bar</p>
</div>
<xsl:attribute name="class">
        <xsl:value-of select="h2/@class"/>
</xsl:attribute>
<xsl:attribute name="class" select="h2/@class"/>