[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Add an element to the result xml document
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|