Results 1 to 4 of 4

Thread: XSLT Function

  1. #1

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    XSLT Function

    Have you ever tried to use a function within an XSL transformation?
    In my case, I followed an online tutorial and came to a conclusion that some functions work, while others don't.

    PHP Code:
      String length: <xsl:value-of select="string-length(artist)" />
                        <
    br />
      
    Current Date: <xsl:value-of select="current-dateTime()" />                    
                        <
    hr /> 
    In this case, string-length(artist) worked for me, but as soon as I put in the current-dateTime, it messes up the output. Can anyone tell me how can I get the XSL to output the current-dateTime()?
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: XSLT Function

    You have a few suggestions to try here.
    http://stackoverflow.com/questions/1...e-current-date

  3. #3

    Thread Starter
    PowerPoster abhijit's Avatar
    Join Date
    Jun 1999
    Location
    Chit Chat Forum.
    Posts
    3,228

    Re: XSLT Function

    Quote Originally Posted by MarkT View Post
    You have a few suggestions to try here.
    http://stackoverflow.com/questions/1...e-current-date
    I have looked at that last night. I did have a go with both the suggestions in that thread. I am attaching the sample XML and XSL file that I have.

    I am using notepad++ with XML Plugins installed.
    Attached Files Attached Files
    Everything that has a computer in will fail. Everything in your life, from a watch to a car to, you know, a radio, to an iPhone, it will fail if it has a computer in it. They should kill the people who made those things.- 'Woz'
    save a blobFileStreamDataTable To Text Filemy blog

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: XSLT Function

    Give this a try for your xsl. You may have to adjust your date format
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited by XMLSpy&#174; -->
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                    xmlns:my="urn:sample" extension-element-prefixes="my">
    
      <msxsl:script language="JScript" implements-prefix="my">
          function today()
          {
            var d = new Date();
            var day = d.getDate();
            var month = d.getMonth();
            var year = d.getYear();
            var curr_date = month + '-' + day + '-' + year;
            return curr_date;
          }
      </msxsl:script>  
    				
    	<xsl:template match="/">
    		<html>
    			<body>
    				<h3>Artists:</h3>
    				<ul>
    					<xsl:for-each select="catalog/cd">
    						<li>
    							<a href="#{generate-id(artist)}">
    								<xsl:value-of select="artist" />
    							</a>
    						</li>
    					</xsl:for-each>
    				</ul>
    				<hr />
    				<xsl:for-each select="catalog/cd">
                Artist: <a name="{generate-id(artist)}">
    						<xsl:value-of select="artist" />
    					</a>
    					<br />
                Title: <xsl:value-of select="title" />
    					<br />
                Price: <xsl:value-of select="price" />
    					<br />
                String length: <xsl:value-of select="string-length(artist)" />
    					<br />
                Current Date: <xsl:value-of select="my:today()" />				
    					<hr />
    				</xsl:for-each>
    			</body>
    		</html>
    	</xsl:template>
    </xsl:stylesheet>

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width