Removing "T" from datetime when doing xml + xsl = html with .net (XmlDataDocument, XslCompiledTransform, XmlTextWriter)

What's the easiest way to remove the "T" from the result?

I want the result to be "YYYY / MM / DD HH / MM / SS"

vb.net code is really straight forward

        xmlDoc = New Xml.XmlDataDocument(data_set)
        xslTran = New Xml.Xsl.XslCompiledTransform
        xslTran.Load(strXslFile)
        writer = New Xml.XmlTextWriter(strHtmlFile, System.Text.Encoding.UTF8)

        xslTran.Transform(xmlDoc, Nothing, writer)

        writer.Close()

      

thank!

0


source to share


2 answers


You can also use the substring-before and substring-after functions in your XSLT file.

<xsl:value-of select="substring-before(@datetime, 'T')" />
<xsl:text> </xsl:text>
<xsl:value-of select="substring-after(@datetime, 'T')"/>

      



Alternatively, you can use the translation function to replace T with a space.

<xsl:value-of select="translate(@datetime,'T',' ')"/>

      

0


source


This is a more readable way to do it:

<xsl:value-of select="substring(., 1, 10)"/>
<xsl:text> </xsl:text>
<xsl:value-of select="substring(., 12, 8)"/>

      



This is less readable, but more concise:

<xsl:value-of select="concat(substring(., 1, 10), ' ', substring(., 12, 8))"/>

      

0


source







All Articles