Solved

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

Posted on 2008-10-23
7
229 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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).

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now