使用.net(XmlDataDocument,XslCompiledTransform,XmlTextWriter)执行xml + xsl = html时从日期时间中删除“T”

时间:2022-01-14 04:37:20

what is the easiest way to remove the "T" from the result?

从结果中删除“T”的最简单方法是什么?

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

我希望结果是“YYYY / MM / DD HH / MM / SS”

the vb.net code is really straight forward

vb.net代码非常简单

        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()

thanks!

2 个解决方案

#1


0  

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

您还可以在XSLT文件中使用substring-before和substring-after函数。

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

Alternatively, you could make use of the translate function, to replace a T with a space.

或者,您可以使用translate函数,用空格替换T.

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

#2


0  

This is a more readable way of doing 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))"/>

#1


0  

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

您还可以在XSLT文件中使用substring-before和substring-after函数。

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

Alternatively, you could make use of the translate function, to replace a T with a space.

或者,您可以使用translate函数,用空格替换T.

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

#2


0  

This is a more readable way of doing 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))"/>