2011-08-08 56 views
-1

我有一個xml如下。複製特定的xml塊

<emp> 
     <Name>Rice</Name> 
     <Designation>Operator</Designation> 
     <sal>$2000</sal> 
     <hobbies><description>1.Playaing Games 2.Watching Movies</description></hobbies> 
    </emp> 
    <emp> 
     <Name>Jeff</Name> 
     <Designation>Admin</Designation> 
     <sal>$1000</sal> 
     <hobbies><description>1.Listening Music</description></hobbies> 
    </emp> 

我需求量的每當標籤<hobbies>遇到我需要複製的愛好部分(<hobbies>1.Playaing Games 2.Watching Movies</hobbies>),因爲它是生成的文件內。 我正在使用xsl從一個xml轉換爲其他xml.My應該看起來像下面。

<EmployeeDetails> 
    Rice,Operator,$2000 
    <hobbies><description>1.Playaing Games 2.Watching Movies</description></hobbies> 
    </EmployeeDetails> 
    <EmployeeDetails> 
    Jeff,Admin,$1000 
    <hobbies><description>1.Listening Music</description></hobbies> 
    </EmployeeDetails> 

請給我一些指示,以達到相同的效果。

回答

0

使用該模板:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="emp"> 
     <EmployeeDetails> 
      <xsl:value-of select="concat(Name, ',', Designation, ',', sal)"/> 

      <xsl:copy-of select="hobbies"/> 
     </EmployeeDetails> 
    </xsl:template> 

</xsl:stylesheet> 

輸出:

<EmployeeDetails> 
    Rice,Operator,$2000<hobbies> 
     <description>1.Playaing Games 2.Watching Movies</description> 
    </hobbies> 
</EmployeeDetails> 
<EmployeeDetails> 
    Jeff,Admin,$1000<hobbies> 
     <description>1.Listening Music</description> 
    </hobbies> 
</EmployeeDetails>