?
Solved

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

Posted on 2008-10-23
7
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

801 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