c# - Date Output (XSLT) -


i'm doing conversion xml format 1 (with updated schema). did xslt altova mapforce , i'm writing program in c# convert documents.

the problem here date format, xslt doing job c# giving me wrong output (20-14-xx-xx).

c# code far:

private void picturebox3_click(object sender, eventargs e) {     openfiledialog open = new openfiledialog();     open.filter = "xml files|*.xml";     if (open.showdialog() == dialogresult.ok)     {         try         {              xdocument xmldocument = xdocument.load(open.filename);             xdocument transformeddoc = new xdocument();              using (xmlwriter writer = transformeddoc.createwriter())             {                 xslcompiledtransform transform = new xslcompiledtransform();                 transform.load(xmlreader.create(new streamreader(@"c:\xslt\converter.xslt")));                 transform.transform(xmldocument.createreader(), writer);             }              savefiledialog savefiledialog = new savefiledialog();             savefiledialog.filter = "xml files|*.xml";             if (savefiledialog.showdialog() == dialogresult.ok)             {                 transformeddoc.save(savefiledialog.filename);             }              {                 messagebox.show("transform complete");             }          }          catch         {             messagebox.show("error");         }     } } 

and line in xslt convert date:

<issuedate>  <xsl:value-of select="translate(format-number(number(string($var8_resultof_first/issuedate)), '####,##,##'), '.,', concat($var13_shared, $var1_resultof_first))"/> </issuedate> 

is possible correct node in c# code?

to format date given as:

<issuedate>20141031</issuedate> 

to:

<issuedate>2014-10-31</issuedate> 

use:

<xsl:value-of select="concat(substring(issuedate, 1, 4), '-', substring(issuedate, 5, 2), '-', substring(issuedate, 7, 2))" /> 

if need more 1 date, use named template:

<xsl:template name="reformat-date">     <xsl:param name="yyyymmdd"/>     <xsl:value-of select="concat(substring($yyyymmdd, 1, 4), '-', substring($yyyymmdd, 5, 2), '-', substring($yyyymmdd, 7, 2))" /> </xsl:template> 

example of call:

<xsl:call-template name="reformat-date">     <xsl:with-param name="yyyymmdd" select="issuedate"/> </xsl:call-template> 

note: cannot use format-number() create groups of digits of unequal size.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -