Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can I format a date in xslt using a defined pattern?

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
Hello,

I'm writing an xsl file in order to write out xml. I have a couple of date fields that I need to format in a specific pattern. Can I do this by creating a named template which defines the pattern? I must format it in the xsl rather than changing .net code.

this is what I'm trying but my node comes back empty.
The template definition (I pulled the value from an XSD file):
Code:
<xsl:template name="DateTimePattern">
  <xsl:param name="thisDate">
  <pattern xmlns="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] value="\d{4}-\d\d-\d\d \d\d:\d\d:\d\d[.]\d\d\d"/>
  </xsl:param>
</xsl:template>
Calling the template
Code:
<xsl:if test="PolicyExpDate!= ''">
  <policy_exp_date>
  <xsl:call-template name="DateTimePattern">
  <xsl:with-param name="thisDate" select="PolicyExpDate"></xsl:with-param>
  </xsl:call-template>
</policy_exp_date>
</xsl:if>

Any help is greatly appreciated. Thanks in advance!
 
You've to use xsl built-in string functions to parse the input data and rebuild the desired datetime string format.
 
Thank you, tsuji. I did end up using string functions but we had some examples already built so I was able to re-use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top