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将带有父节点的节点移动到每个父节点中';s具有给定属性的同级_Xslt - Fatal编程技术网

XSLT将带有父节点的节点移动到每个父节点中';s具有给定属性的同级

XSLT将带有父节点的节点移动到每个父节点中';s具有给定属性的同级,xslt,Xslt,我有以下源代码a.html: <html> <head> <title>title</title> </head> <body> <div class="a">a <div class="a1">a1</div> <div class="x" type="typea2">x <div class="x1"

我有以下源代码a.html:

<html>
  <head>
    <title>title</title>
  </head>
  <body>
    <div class="a">a
      <div class="a1">a1</div>
      <div class="x" type="typea2">x
        <div class="x1">x1</div>
      </div>
      <div class="a3">a3</div>
    </div>
    <div class="b">b_1
      <div class="b1">b1_1</div>
      <div class="b3">b3_11</div>
      <div class="b3">b3_12</div>
      <div class="b3">b3_13</div>
    </div>
    <div class="b">b_2
      <div class="b1">b1_2</div>
      <div class="b3">b3_21</div>
      <div class="b3">b3_22</div>
    <div class="b">b_3
      <div class="b1">b1_3</div>
      <div class="b3">b3_31</div>
      <div class="b3">b3_32</div>
      <div class="b3">b3_33</div>
      <div class="b3">b3_34</div>
    </div>
  </body>
</html>
使用以下a.xslt:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <!-- ignore x-inside-a -->
 <xsl:template match="//div[@class='a']/div[@class='x']"/>

 <!-- place the x-inside-a into each b after text() and b1 -->
 <xsl:template match="div[@class='b']">
  <xsl:copy>
   <xsl:copy-of select="//div[@class='a']/div[@class='x']" />
   <xsl:apply-templates />
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>

然而,我没有得到想要的结果


我可以请求您的帮助吗?

如果内部
div
始终存在,我会为它编写一个模板:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <!-- ignore x-inside-a -->
 <xsl:template match="div[@class='a']/div[@class='x']"/>

 <!-- place the x-inside-a into each b after b1 -->
 <xsl:template match="div[@class='b']/div[@class = 'b1']">
  <xsl:call-template name="identity"/>
  <xsl:copy-of select="//div[@class='a']/div[@class='x']" />
 </xsl:template>

</xsl:stylesheet>

div class=“b”
中是否总是有一个
div class=“b1”
?如果
div class=“b1”
不存在,您想在哪里插入另一个
div
。是的,div class=“b1”始终存在于div class=“b”中。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <!-- ignore x-inside-a -->
 <xsl:template match="//div[@class='a']/div[@class='x']"/>

 <!-- place the x-inside-a into each b after text() and b1 -->
 <xsl:template match="div[@class='b']">
  <xsl:copy>
   <xsl:copy-of select="//div[@class='a']/div[@class='x']" />
   <xsl:apply-templates />
  </xsl:copy>
 </xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <!-- ignore x-inside-a -->
 <xsl:template match="div[@class='a']/div[@class='x']"/>

 <!-- place the x-inside-a into each b after b1 -->
 <xsl:template match="div[@class='b']/div[@class = 'b1']">
  <xsl:call-template name="identity"/>
  <xsl:copy-of select="//div[@class='a']/div[@class='x']" />
 </xsl:template>

</xsl:stylesheet>