Solved

How do I add an xslt date to these two files?

Posted on 2008-10-23
7
232 Views
Last Modified: 2013-11-18
I want to place  the string "Released created on date/time" on build machine XXXXX

beneath the "Release Software Components" statement using xslt.

Note: to see what this looks like copy the xml and .xsl inbto the same directory and double click on the .xml
This is the xml file/code
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
	<!-- Edited by XMLSpy® -->
<carefx>
	<component>
		<Component>CM-Client</Component>
		<Release>3.1</Release>		
	</component>	
</carefx>
 
 
here is the.xsl
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
 
<xsl:template match="/">
  <html>
  <body>
  <h2>Release Software Components</h2>	  
    <table border="1">
      <tr bgcolor="#9acd32">
        <th align="left">Component</th>
        <th align="left">Release</th>
      </tr>
      <xsl:for-each select="carefx/component">
      <tr>
        <td><xsl:value-of select="Component"/></td>
        <td><xsl:value-of select="Release"/></td>
      </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

Open in new window

0
Comment
Question by:Christopher Schene
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22793961
Well, putting that literal string there is easy, but I assume that you really want the current date there.

There are some options for doing so, but basically there is a no-size-fits-all
- if you can use XSLT2, it is easy, just use the current-date() function. I see you are using XMLSpy. XML SPy has its own XSLT2 processor (though it sucks)
- if you use a processor that supports exslt (www.exslt.org) use the date:date function there (let me know how you are processing this and I can help you)
- use an extension function (JavaScript for msxml, C# for .net transformer, java for Xalan and Saxon, though the later two support exslt)
- pass the date as a parameter in from outside

BUT.
Since you are passing the XSLT to the XML using xml-stylesheet, I assume you want this in a browser.
If that is the case, you have no other option than using a JavaScript function to call the XSLT.
Since the browsers all have different XSLT processors, you need a solution for multiple processors.
You have little option but using something like Sarissa (for cross browser JavaScript/XML) and passing the date as a parameter

As you see, the answer to your question is very much dependent on how you are doing the XSLT.
Can you tell us how you plan to process the XSLT, so  we can help you with the next step

Cheers

Geert
0
 

Author Comment

by:Christopher Schene
ID: 22798041
I am using IE 6 to process this.

Would you please show me how I would set the current date using JScript?
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 22798129
Here you go,
This will work in IE, but for reasons explainde earlier, this will not work in other browsers
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    extension-element-prefixes="date msxsl">
    
    <msxsl:script language="JScript" implements-prefix="date">
        <![CDATA[
	function date(){
		var oDate = new Date();
		var ret = "";
		var m = oDate.getMonth() + 1;
	    var mm = m < 10 ? "0" + m : m;
		ret = ret + mm + "/";
		var d = oDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		ret = ret + dd + "/";
		ret = ret + oDate.getFullYear();
		return ret;
		}
	]]>
    </msxsl:script>
 
    <xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
    
    <xsl:template match="/">
        <html>
            <body>
                <h2>Release Software Components</h2>
                <h3>
                    <xsl:text>Released created on </xsl:text>
                    <xsl:value-of select="date:date()"/>
                </h3>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th align="left">Component</th>
                        <th align="left">Release</th>
                    </tr>
                    <xsl:for-each select="carefx/component">
                        <tr>
                            <td><xsl:value-of select="Component"/></td>
                            <td><xsl:value-of select="Release"/></td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Christopher Schene
ID: 22798454
That did not work for me.....see bitmap and xslt code
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"	
    xmlns:date="http://exslt.org/dates-and-times"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"				
    extension-element-prefixes="date msxsl">
 
	<msxsl:script language="JScript" implements-prefix="date">
		<![CDATA[
	function date(){
		var oDate = new Date();
		var ret = "";
		var m = oDate.getMonth() + 1;
	    var mm = m < 10 ? "0" + m : m;
		ret = ret + mm + "/";
		var d = oDate.getDate();
		var dd = d < 10 ? "0" + d : d;
		ret = ret + dd + "/";
		ret = ret + oDate.getFullYear();
		return ret;
		}
	]]>
	</msxsl:script>
 
	<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
	<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
 
	<xsl:template match="/">
		<html>
			<body>
				<h2>Release Software Components</h2>
				<h3>
					<xsl:text>Released created on </xsl:text>
					<xsl:value-of select="date:date()"/>
				</h3>
				<table border="1">
					<tr bgcolor="#9acd32">
						<th align="left">Component</th>
						<th align="left">Release</th>
					</tr>
					<xsl:for-each select="carefx/component">
						<tr>
							<td>
								<xsl:value-of select="Component"/>
							</td>
							<td>
								<xsl:value-of select="Release"/>
							</td>
						</tr>
					</xsl:for-each>
				</table>
			</body>
		</html>
	</xsl:template>
</xsl:stylesheet>

Open in new window

xslt-output.bmp
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22798482
of course not.
What I sent is the XSLT.
So you need to save it as cdcatalog.xsl
and open the xml file, with reference to this XSLT
like you had in your original question

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
      <!-- Edited by XMLSpy® -->
<carefx>
      <component>
            <Component>CM-Client</Component>
            <Release>3.1</Release>            
      </component>      
</carefx>
 
0
 

Author Comment

by:Christopher Schene
ID: 22799444
Ok, I am a beginner at xslt....When I set it up the way you instructed it worked.

You have the points. Thanks.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22799453
welcome
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question