亲爱的朋友们,下午好.我的问题可能是这是非常基本的问题,即我们如何使用xslt从xml文件中删除根元素.下面给出的Xml文件示例.
<Result> <Jobs id="1"> <Job ID="000000" PositionID="0000"> <Title>Development Manager - Investment Banking - Equities Business</Title> <Summary><![CDATA[An experienced Development Manager with prevIoUs experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role,you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.   My client,a well known investment bank,requires an experienced Development Manager to join their core technology team. This t]]></Summary> <DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive> <DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires> <DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated> <CompanyName>ABC Technology</CompanyName> </Job> </Jobs> </Result>
所以,我想要输出如下
<Jobs> <Job ID="000000" PositionID="0000"> <Title>Development Manager - Investment Banking - Equities Business</Title> <Summary><![CDATA[An experienced Development Manager with prevIoUs experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role,requires an experienced Development Manager to join their core technology team. This t]]></Summary> <DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive> <DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires> <DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated> <CompanyName>ABC Technology</CompanyName> </Job> </Jobs>
所以,不再
<Result></Result>
<!-- identity template --> <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*" /> </xsl:copy> </xsl:template> <!-- template for the document element --> <xsl:template match="/*"> <xsl:apply-templates select="node()" /> </xsl:template>
身份模板按原样复制所有内容,而文档元素的模板仅处理子节点(将它们交给身份模板),而不复制根节点本身.
如果你想保留你的< summary>由于某种原因,你需要CDATA
<xsl:output cdata-section-elements="summary" />