Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2006, 12:00 PM
Registered User
 
Join Date: Nov 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calling javascript without user interaction

I'm a total xslt newbie looking for what, I'm sure, is not a difficult answer.

I am processing an rss feed and displaying it on a page. I am trying to massage an xslt file to have it display the way I need it. The way the code is currently written, the title of the rss feed is displayed on the page, and the user needs to click on a "+" next to the title of the feed to display its contents. I am trying to have it so that the contents are displayed automatically without the user having to hit the expand button to view the details.

So currently the page looks like this

Yahoo! Weather - Jacksonville, FL
+ Conditions for Jacksonville, FL at 9:53 am EST

When the user clicks on the +, the details of the feed are displayed below it (the topic is expanded).

I would like it to look like this without the user having to click the +:

Yahoo! Weather - Jacksonville, FL
- Conditions for Jacksonville, FL at 9:53 am EST

Current Conditions:
Mostly Cloudy/Windy, 65 F

Forecast:
Fri - Partly Cloudy/Wind. High: 65 Low: 43
Sat - Mostly Sunny. High: 67 Low: 48

Full Forecast at Yahoo! Weather
(provided by The Weather Channel)


Here is the code. I've omitted an irrelevant portion that diplays the various templates that are determined by the content of the feed:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rss="http://purl.org/rss/1.0/" xmlns:rdf09="http://my.netscape.com/rdf/simple/0.9/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <xsl:output method="html" indent="yes" />
    <xsl:template name="includeScript">
        <style type="text/css">
            <![CDATA[
                .Header
                {
                    background-color: #f1f1f1;
                }
                .Header a, .Header a:active, .Header a:visited, .Header a:hover
                {
                    color: black;
                    text-decoration: none;
                }
                .HeaderCollapse
                {
                    background-color: #f1f1f1;
                    font-weight: bold;
                    padding-left: 0.2em;
                    width: 17px;
                }
                .HeaderCollapse a, .HeaderCollapse a:visited, .HeaderCollapse a:active, .HeaderCollapse a:hover
                {
                    background-color: white;
                    border: 1px #707070 solid;
                    color: black;
                    display: block;
                    font-family: Tahoma, Verdana, Sans-Serif;
                    font-size: 8px;
                    height: 10px;
                    text-decoration: none;
                    width: 10px;
                }
                .Content
                {
                    margin-top: -16px;
                }


              ]]>
        </style>
        <script language="JavaScript" type="text/javascript">
            <![CDATA[
                function ExpGroup(szID, oElement)
                {
                    var oID = document.getElementById(szID);
                    if (oElement.innerHTML == "-")
                    {
                        oElement.innerHTML = "+";
                        oElement.title= "Expand";
                        oID.style.display = "none";
                    }
                    else
                    {
                        oElement.innerHTML = "-";
                        oElement.title= "Collapse";
                        oID.style.display = "block";
                    }
                    try
                    {
                        window.event.returnValue = false;
                        window.event.cancelBubble = true;
                    }
                    catch (e) { }
                }


              ]]>
        </script>
    </xsl:template>
    <xsl:template match="rdf:RDF">
        <xsl:variable name="IsEmptyRSS" select="not (rss:channel/rss:title)" />
         <xsl:variable name="IsEmptyRDF" select="not (rdf09:channel/rdf09:title)" />
        <xsl:choose>
            <xsl:when test="not ($IsEmptyRDF)">
                <xsl:call-template name="rdf_09" />
            </xsl:when>
            <xsl:when test="not ($IsEmptyRSS)">
                <xsl:call-template name="rss_1" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="rss_1" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template match="rss">
        <xsl:choose>
            <xsl:when test="@version = '2.0'">
                <xsl:call-template name="rss_2" />
              </xsl:when>
             <xsl:when test="@version = '0.91'">
                  <xsl:call-template name="rss_091" />
              </xsl:when>
             <xsl:when test="@version = '0.92'">
                  <xsl:call-template name="rss_092" />
              </xsl:when>
             <xsl:otherwise>
                  <xsl:call-template name="rss" />
              </xsl:otherwise>
          </xsl:choose>
      </xsl:template>
     <xsl:template name="rss_2">
          <xsl:call-template name="includeScript" />
             <div align="center">
                 <h3>
                     <a target="_blank">
                         <xsl:attribute name="title">
                             <xsl:value-of select="channel/description" />
                          </xsl:attribute>
                         <xsl:attribute name="href">
                              <xsl:value-of select="channel/link" />
                          </xsl:attribute>
                          <xsl:value-of select="channel/title" />
                      </a>
                  </h3>
              </div>
             <div style="padding-left: 5px; padding-right: 5px; padding-bottom: 5px;">
                 <table class="Content" cellspacing="0" cellpadding="1">
                     <xsl:for-each select="channel/item">
                          <xsl:variable name="TopicID" select="generate-id(link)" />
                         <tr>
                         <td class="HeaderCollapse" align="center">
                         <a style="cursor: pointer; cursor: hand;" title="Expand">
                             <xsl:attribute name="onclick">
                              javascript:ExpGroup('<xsl:value-of select="$TopicID" />', this)
                              </xsl:attribute>
                              +
                          </a>
                          </td>
                         <td class="Header" style="width: 100%">
                             <a target="_blank">
                             <xsl:choose>
                               <xsl:when test="guid != ''">
                                 <xsl:attribute name="href">
                                    <xsl:value-of select="guid" />
                                  </xsl:attribute>
                                </xsl:when>
                               <xsl:otherwise>
                                 <xsl:attribute name="href">
                                    <xsl:value-of select="link" />
                                  </xsl:attribute>
                                </xsl:otherwise>
                              </xsl:choose>
                             <xsl:choose>
                               <xsl:when test="title != ''">
                                  <xsl:value-of select="title" />
                                </xsl:when>
                               <xsl:when test="guid != ''">
                                <xsl:value-of select="guid" />
                              </xsl:when>
                               <xsl:otherwise>
                                <xsl:value-of select="link" />
                              </xsl:otherwise>
                              </xsl:choose>
                              </a>
                          </td>
                          </tr>
                         <tr>
                           <td colspan="2">
                             <div style="display: none; padding-top: 0.25em; padding-bottom: 0.25em; padding-left: 10px; padding-right: 10px;">
                             <xsl:attribute name="id">
                                <xsl:value-of select="$TopicID" />
                              </xsl:attribute>
                              <xsl:variable name="IsEmpty" select="not (description)" />
                               <xsl:choose>
                                 <xsl:when test="description = ''">
                                  <xsl:text disable-output-escaping="yes">No description available</xsl:text>
                                  </xsl:when>
                                 <xsl:when test="not ($IsEmpty)">
                                  <xsl:value-of disable-output-escaping="yes" select="description" />
                                  </xsl:when>
                                 <xsl:otherwise>
                                  <xsl:text disable-output-escaping="yes">No description available</xsl:text>
                                  </xsl:otherwise>
                                </xsl:choose>
                               </div>
                            </td>
                          </tr>
                      </xsl:for-each>
                  </table>
              </div>
          </xsl:template>
  </xsl:stylesheet>

 
Old November 3rd, 2006, 12:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Work out what HTML/CSS you want to generate. That's an HTML problem, not an XSLT problem. Then make the corresponding changes to your stylesheet. I don't think this will affect the XSLT code at all, only the textual content of the style element that it's generating.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
calling template with javascript smys123 XSLT 3 November 22nd, 2007 04:13 AM
User interaction... Don Herman Access 3 January 31st, 2006 08:48 AM
Calling WS from javascript r_ganesh76 Javascript 5 December 8th, 2004 05:31 AM
calling javascript from flash Adam H-W Flash (all versions) 2 March 17th, 2004 11:26 AM
calling webservices from Javascript.. wb25 J2EE 1 February 20th, 2004 10:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.