Solved

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

Posted on 2008-10-23
7
230 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:cschene
  • 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:cschene
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:cschene
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:cschene
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

774 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