• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

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

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
Christopher Schene
Asked:
Christopher Schene
  • 4
  • 3
1 Solution
 
Geert BormansCommented:
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
 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
I am using IE 6 to process this.

Would you please show me how I would set the current date using JScript?
0
 
Geert BormansCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
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
 
Geert BormansCommented:
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
 
Christopher ScheneSystem Engineer/Software EngineerAuthor Commented:
Ok, I am a beginner at xslt....When I set it up the way you instructed it worked.

You have the points. Thanks.
0
 
Geert BormansCommented:
welcome
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now