Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying a random item of an XML file in an HTML page 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
I posted the linked thread over 2 weeks ago in the XML forum and got no joy, just wondered if anyone here had any ideas: thread426-839056.

Your help would be much appreciated!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Quotes.xml is a file I wrote manually i.e. it wasn't generated by anything other than my hands typing the info into notepad. It's structure is as follows:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style_sheet.xsl"?>
<QUOTES>
 <QUOTE>
  <TEXT>...</TEXT>
  <PASSAGE>...</PASSAGE>
 </QUOTE>
</QUOTES>
...

The style_sheet.xsl file looks like this:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns="[URL unfurl="true"]http://www.w3.org/TR/xhtml1/strict">[/URL]
  <body style="font-family:tahoma,helvetica,sans-serif;font-size:12pt;
        background-color:#000000">
    <xsl:for-each select="QUOTES/QUOTE">
      <div style="background-color:black;color:white;padding:4px">
        <span style="font-weight:bold;color:white">
        <xsl:value-of select="TEXT"/></span>
        - <xsl:value-of select="PASSAGE"/>
      </div>
    </xsl:for-each>
  </body>
</html>

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
In that case... everything is OK with X(HT)ML/XSL and problem is pure javascript:
Code:
<body onload="randomQuote();">
...
<script language="javascript">
function randomQuote()
{	with( Quotes.recordset )
	{	iRec = Math.floor( Math.random() * recordCount );
		moveFirst();
		move ( iRec );
	}
}
</script>
 
Thanks for the prompt answer vongrunt, that worked brilliantly. A star for you.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top