mdeepthi.89 Posted July 8, 2011 Share Posted July 8, 2011 I'm new to XML and XSL.my XMl source is :<root> <row> <id> <name> </row> <row> <id> <name></row></root>I want my output as:<root> <user>abc</user> <created date>23-05-2011</created date> <row> <id> <name> </row> <row> <id> <name></row></root>So How do I create a new node which is not there in the source XMl and also could you please tell me how can i get the current date.Thanks a lot. Link to comment Share on other sites More sharing options...
Martin Honnen Posted July 9, 2011 Share Posted July 9, 2011 What you have posted as the "XML" source is not even well-formed XML so it is hard to tell what you want to achieve.Try whether <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy></xsl:template><xsl:template match="root"> <xsl:copy> <xsl:apply-templates select="@*"/> <user>abc</user> <date-created> <xsl:value-of select="format-date(current-date( ), '[D01]-[M01]-[Y0001]')"/> </date-created> <xsl:apply-templates/> </xsl:copy></xsl:template></xsl:stylesheet> That is an XSLT 2.0 stylesheet you can run with XSLT 2.0 processors like Saxon 9 or AltovaXML or XQSharp. Link to comment Share on other sites More sharing options...
mdeepthi.89 Posted July 11, 2011 Author Share Posted July 11, 2011 What you have posted as the "XML" source is not even well-formed XML so it is hard to tell what you want to achieve.Try whether<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:template match="@* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy></xsl:template><xsl:template match="root"> <xsl:copy> <xsl:apply-templates select="@*"/> <user>abc</user> <date-created> <xsl:value-of select="format-date(current-date( ), '[D01]-[M01]-[Y0001]')"/> </date-created> <xsl:apply-templates/> </xsl:copy></xsl:template></xsl:stylesheet> That is an XSLT 2.0 stylesheet you can run with XSLT 2.0 processors like Saxon 9 or AltovaXML or XQSharp. I'm sorry about that.I will to rephrase my question.How do i create a node in my output xml file which does not exist in source xml file. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.