Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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复制xml内部文本_Xml_Xslt - Fatal编程技术网

使用xslt复制xml内部文本

使用xslt复制xml内部文本,xml,xslt,Xml,Xslt,我有一个具有以下结构的xml: 我需要一个xslt来仅复制“library\u animation\u clips”节点中的innertext,以便输出xml如下所示: <Renderer Type="ThreeD"> <ThreeDRenderer> <animation_clip id="intro" start="0.25" end="1.25" start_pos="0.25" speed="1" loop="f

我有一个具有以下结构的xml:


我需要一个xslt来仅复制“library\u animation\u clips”节点中的innertext,以便输出xml如下所示:

<Renderer Type="ThreeD">
        <ThreeDRenderer>
            <animation_clip id="intro" start="0.25" end="1.25" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="outro" start="1.26" end="2.26" start_pos="1.26" speed="1" loop="false" reverse="false"/>
            <animation_clip id="disabled" start="2.27" end="2.27" start_pos="2.27" speed="1" loop="false" reverse="false"/>
            <animation_clip id="active" start="2.28" end="2.28" start_pos="2.28" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i0_p" start="2.29" end="3.10" start_pos="2.29" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i0_i2_n" start="3.11" end="3.12" start_pos="3.11" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i1_i0_p" start="3.13" end="3.14" start_pos="3.16" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i1_i2_n" start="3.15" end="3.16" start_pos="3.17" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i2_i1_p" start="3.17" end="3.18" start_pos="3.18" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i2_i3_n" start="3.19" end="3.20" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i3_i2_p" start="3.21" end="3.22" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i3_i4_n" start="3.23" end="3.24" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i4_i3_p" start="3.25" end="3.26" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i4_i5_n" start="3.27" end="3.28" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i5_i4_p" start="3.29" end="3.30" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i5_i6_n" start="3.31" end="3.32" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i6_i5_p" start="3.33" end="3.34" start_pos="0.25" speed="1" loop="false" reverse="false"/>
            <animation_clip id="i6_n" start="3.35" end="3.36" start_pos="0.25" speed="1" loop="false" reverse="false"/>
        </ThreeDRenderer>
    </Renderer>


请告诉我如何实现这一点?

以下小样式表应该可以完成这项工作:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="metadata">
    <Renderer Type="ThreeD">
      <ThreeDRenderer>
        <xsl:apply-templates select="library_animation_clips/*"/>
      </ThreeDRenderer>
    </Renderer>
  </xsl:template>

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

第二个模板如何知道要复制哪些节点?
告诉处理器继续与库动画剪辑的子元素匹配模板。由于动画剪辑元素没有显式模板,因此使用pattern
node()
的更通用模板将匹配并应用。此模板复制完整的上下文节点。或者,您也可以删除第二个模板并用
替换
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="metadata">
    <Renderer Type="ThreeD">
      <ThreeDRenderer>
        <xsl:apply-templates select="library_animation_clips/*"/>
      </ThreeDRenderer>
    </Renderer>
  </xsl:template>

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