2009-10-15 19 views
5

Cari amici buon pomeriggio. Il mio problema potrebbe essere che questo è molto semplice e come possiamo rimuovere l'elemento root da un file xml usando xslt. Esempio di file Xml indicato di seguito.Come rimuovere l'elemento root dal file 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.&#160;&#160; 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> 

Quindi, voglio l'output come di seguito

<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, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.&#160;&#160; 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> 

Quindi, non più

<Result></Result> 

tag nel file xml. Pls. Aiuto. Grazie in anticipo.

+1

è possibile formattare la tua domanda in modo che possiamo vedere che cosa è il vostro chiedono? sembra che tu debba risolvere < – Rippo

risposta

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

L'identità copie di modello tutto così com'è, mentre il modello per l'elemento del documento si prende cura solo dei nodi figlio (di consegnarli al modello di identità), mentre non è la copia del nodo radice stessa.

Se si desidera mantenere la <summary> come CDATA per qualche motivo, è necessario

<xsl:output cdata-section-elements="summary" /> 
+1

Questo modo di copiare elementi e giocare con loro mi ha aiutato molto in XSLT. Grazie mille per questa risposta. –

+0

@geekam Grazie per il vostro feedback! :) – Tomalak

Problemi correlati