Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 3rd, 2006, 11:09 AM
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recursive Function

My input XML has dates in the format yyyymmdd (20060503) & my target XML output needs dates in the format dd mmmmm yyyy (3 May 2006). I've used the following to re-format:

Code:
        <xsl:choose>
          <xsl:when test="substring(BookingData/GeneralInformation/PNRCreationDate,5,2)='01'">
            <xsl:value-of select="concat(substring(BookingData/GeneralInformation/PNRCreationDate,7,2), 
              ' January ' , substring(BookingData/GeneralInformation/PNRCreationDate,1,4))" />
          </xsl:when>
          <xsl:when test="substring(BookingData/GeneralInformation/PNRCreationDate,5,2)='02'">
            <xsl:value-of select="concat(substring(BookingData/GeneralInformation/PNRCreationDate,7,2), 
              ' February ' , substring(BookingData/GeneralInformation/PNRCreationDate,1,4))" />
          </xsl:when>   etc.....


long-winded, but it works. However each XML file has at least 3 dates which means I'm replicating the same logic for each one. Is there a way of "calling a function" so I only have one piece of date-formatting code? or at worst is there an easy way of determining the month name instead of the way I'm doing it (some sort of array lookup in programming terms)

as always - thanks in advance.


 
Old May 3rd, 2006, 11:32 PM
Authorized User
 
Join Date: Apr 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vakorde
Default

Why don't u wrote a function in XSL i.e. a template
<xsl:template name="convertDate">
  <xsl:param name="str" select="'20060503'" />
  <xsl:choose>
          <xsl:when test="substring($str,5,2)='01'">
            <xsl:value-of select="concat(substring($str,7,2),
              ' January ' , substring($str,1,4))" />
          </xsl:when>
          <xsl:when test="substring($str,5,2)='02'">
            <xsl:value-of select="concat(substring($str,7,2),
              ' February ' , substring($str,1,4))" />
          </xsl:when>
           ..........
   </xsl:choose>
</xsl:template>

for calling this fucntion you can use this code
<xsl:call-template name="convertDate">
  <xsl:with-param name="str" select="BookingData/GeneralInformation/PNRCreationDate"/>
</xsl:call-template>

This will solve ur problem, you don't need a recursive function for this.

 
Old May 4th, 2006, 02:52 AM
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

COOL !

Many thanks vakorde

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive function problem cnatale XSLT 2 April 3rd, 2008 03:11 AM
How to create a recursive function for combobox [email protected] PHP How-To 0 May 5th, 2007 04:04 AM
Recursive template - Please Help! Tre XSLT 5 March 20th, 2007 11:23 AM
Recursive Transform chuck.boyer XSLT 0 December 5th, 2005 05:51 PM
Help:Recursive Function - attributes into elements spencer.clark XSLT 1 June 10th, 2005 07:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.