2012-05-07 65 views
0

我有具有以下結構的XML: 複製XML的innerText使用XSLT

<metadata style="basic"> 
    <zonelist> 
     <zone name="z0" type="poster" id="null" x="558" y="1550" w="180" h="260"/> 
     <zone name="z1" type="poster" id="null" x="738" y="1550" w="180" h="260"/> 
     <zone name="z2" type="poster" id="null" x="918" y="1550" w="180" h="260"/> 
     <zone name="z3" type="poster" id="null" x="1098" y="1550" w="180" h="260"/> 
     <zone name="z4" type="poster" id="null" x="1278" y="1550" w="180" h="260"/> 
     <zone name="z5" type="poster" id="null" x="1458" y="1550" w="180" h="260"/> 
     <zone name="z6" type="poster" id="null" x="1638" y="1550" w="180" h="260"/> 
    </zonelist> 
    <library_animation_clips> 
     <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"/> 
    </library_animation_clips> 
</metadata> 

我需要一個XSLT,使輸出的XML看起來像只的innerText從「library_animation_clips」節點複製:

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

請讓我知道我該怎麼做到這一點?

回答

1

下面小編樣式應該做的工作:

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

感謝。有效。你能簡單地向我解釋它是如何工作的嗎? –

+0

第二個模板如何知道要複製哪些節點? –

+0

''告訴處理器繼續使用_library_animation_clips_的子元素進行模板匹配。由於_animation_clip_元素沒有明確的模板,所以具有'node()'模式的更一般模板匹配並被應用。該模板複製完整的上下文節點。或者,您也可以刪除第二個模板,並用''替換''。 – Martin