Subject: RE: [xsl] Add an element to the result xml document From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx> Date: Tue, 8 Oct 2002 09:58:27 +0100 |
> I have sucessfully copied all the elements in source xml to > result xml but I also want duplicates of some elements. In > the partial xml doc below I want the result to contain two > copies of the <MessageID> and </MessageID> elements. > > I am using this XSLT: > > <!-- copy all the elements to the result document --> > <xsl:template match="/"> > <xsl:copy-of select="."/> > </xsl:template> Anything else in your stylesheet is irrelevant. You come in at the root node, you copy the entire source tree to the output, and you exit. The simplest transformation there is. Not hard to be successful at that one! If you want to do anything other that a straight copy, the first thing to do is to get rid of the <xsl:copy-of> and write <xsl:apply-templates>. Then you can start writing template rules that describe how you want each node to be processed. By default you probably want nodes unchanged, so write <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> and then add template rules for any nodes which you don't want to copy exactly. For example (I can't see why you would want to do this): <xsl:template match="MessageID"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> <!-- and again... --> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Add an element to the res, Joerg Heinicke | Thread | RE: [xsl] Add an element to the res, LVanvleet |
RE: [xsl] data structure in xslt?, Michael Kay | Date | RE: [xsl] Expected behavior for par, Michael Kay |
Month |