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!

And operator (or a better way?) 1

Status
Not open for further replies.

Delameko

Programmer
Oct 14, 2003
37
GB
Hi,

this is a follow-up to this thread.

I've tried a load of different things but I can't get any to work, and I feel like I'm missing something.

I need to sort my entries by the venueID. I don't need to do it dynamically (at this stage anyway). I need to be able to alter the xsl to say 'show only entries with 'this' venueID.

Here's the XML (simplified) from the previous thread:
Code:
<listing>
    <titleList>
        <title titleID="someID">
            <titleName>Land Of the Dead</titleName>
        </title>

        <title... etc etc
    </titleList>

    <eventList>
        <event titleID="txsahara" [COLOR=#ff0000]venueID="vxromste"[/color]
>
            <originalTimes>Progs 11.15am 2.15pm 5.15pm</originalTimes>
        </event>

        <event... etc etc
    </eventList>
</listing>

and here's the code that JontyMC provided:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
      <xsl:apply-templates select="listing/eventList"/>
  </xsl:template>
  <xsl:template match="eventList">
    <ul>
      <xsl:apply-templates select="event"/>
    </ul>
  </xsl:template>
  <xsl:template match="event">
    <li>
      <xsl:value-of select="../../titleList/title[@titleID = current()/@titleID]/titleName"/> - <xsl:value-of select="originalTimes"/>
    </li>
  </xsl:template>
</xsl:stylesheet>


I saw AND being used in another thread, but it was a different situation and I could get it to work.

Any help would be greatly appreciated.

Thanks in advance.
 
Best way to do this is to only apply-templates to the node you are concerned with (event with a particular venueID):
Code:
<xsl:apply-templates select="event[@venueID = 'blah']"/>
I don't think sorting is what you want to do here, but it's simple. Just put a sort under the with the apply-templates:
Code:
<xsl:apply-templates select="event">
  <xsl:sort select="@venueID"/>
</xsl:apply-templates>
To apply-templates dynamically, it depends on what server-side (although you can do it in JavaScript) language you are using. Normally you'd just use a parameter. Can give you an example if you want (specify your language).

Jon

"I don't regret this, but I both rue and lament it.
 
Thats weird, I tried the first way before and it didn't work... now it does.

You must have the magic touch Jonty [wink]

Thanks again, wouldn't have been able to do it without you.
 
To apply-templates dynamically, it depends on what server-side (although you can do it in JavaScript) language you are using. Normally you'd just use a parameter. Can give you an example if you want (specify your language).

You can if you want [smile], I'm using JavaScript. Might as well get a headstart, I'm gonna have to tackle it eventually anyway. Thanks.
 
Whats the code for your transform at the moment then?

Jon

"I don't regret this, but I both rue and lament it.
 
Code:
        <SCRIPT language="JScript" defer="true">
            var xml = new ActiveXObject("Msxml2.DOMDocument.3.0");
            xml.async = false;
            xml.onreadystatechange=verify;
            
            function verify()
				{
						// 0 Object is not initialized
						// 1 Loading object is loading data
						// 2 Loaded object has loaded data
						// 3 Data from object can be worked with
						// 4 Object completely initialized
  					if (xml.readyState != 4)
  					{
      				return false;
  					}
				}

            
            xml.load("Cinema.xml");

            function showCinema()
            {

                var xsl = new ActiveXObject("Msxml2.DOMDocument.3.0");
                xsl.async = false;
                xsl.load("Cinema1.xsl");
 
                var mypop=window.open('CinemaPopup.html','newwin','scrollbars=yes,menubar=no,height=600,width=510,resizable=no,toolbar=no,location=no,status=no');
                mypop.document.getElementsByTagName('body')[0].innerHTML=xml.transformNode(xsl);


            }


Thanks.
 
Oops, posted wrong document. Something to be said for not posting just as you're on your way out the door... [upsidedown]

Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]


  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
         <img src="[URL unfurl="true"]http://content.thisis.co.uk/mid/Lincolnshire/new_entertainment/heading_cinema.jpg"[/URL] width="481" height="89" align="top" alt="Cinema Listings"/><br />
      <div class="date" align="centre">      
         <table>
            <tr>
               <td height="40" valign="middle">
                  <u>Films showing from <xsl:value-of select="listing/eventList/event/startDate" /></u>
               </td>
            </tr>
         </table>
      </div>
      <xsl:apply-templates select="listing/eventList"/>
  </xsl:template>

  <xsl:template match="eventList">
    <table>
      <xsl:apply-templates select="event[@venueID = 'vxromste']"/>
    </table>
  </xsl:template>

  <xsl:template match="event">
    <tr>
      <td width="450" align="left" valign="bottom" bgcolor="#1875A5">
        <div class="title">
        <xsl:value-of select="../../titleList/title[@titleID = current()/@titleID]/titleName"/>
        </div>
      </td>
    </tr>
    <tr>
      <td width="450">
        <table height="50" align="centre" valign="top">
          <tr>
            <td width="400">
              <div class="times"><xsl:value-of select="originalTimes"/></div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </xsl:template>

</xsl:stylesheet>
 
Change your showCinema function to:
Code:
function showCinema(venueID)
{
    var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
    xsl.async = false;
    xsl.load("a.xsl");
    var temp = new ActiveXObject("MSXML2.XSLTemplate");
    temp.stylesheet = xsl;
    var proc = temp.createProcessor();
    proc.addParameter("venueID", venueID);
    proc.input = xml;
    proc.transform();
    var str = proc.output;
    var mypop=window.open('test.htm','newwin','scrollbars=yes,menubar=no,height=600,width=510,resizable=no,toolbar=no,location=no,status=no');
    mypop.document.getElementsByTagName('body')[0].innerHTML = str;
}
And call it with (e.g.):
Code:
onclick="javascript: showCinema('vxromste');"
Now add a param to your stylesheet:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="venueID"/>
  <xsl:template match="/">
  .....................
And reference that param when applying templates:
Code:
  <xsl:template match="eventList">
    <table>
      <xsl:apply-templates select="event[@venueID = $venueID]"/>
    </table>
  </xsl:template>
Bear in mind that JavaScript isn't the best place to do the transform. This code is IE only (although you could adapt it to mozilla). Much better to do the transform server-side, then its always gonna be cross-browser.

Jon

"I don't regret this, but I both rue and lament it.
 
Awesome!

You've done again Jonty! [glasses]

I think at this point I would've prefered to do it with asp. But when it started it seemed a lot simpler, and my boss started adding things he wanted and I finally got to see the xml and by that point I'd invested to much time to start from scratch (in his eyes). Oh well, its been a good learning experience and when he sees how slow its gonna run I'm sure he'll start thinking about 'upgrading' [smile].

And the site I'm doing this for doesn't even support firefox anyway, my boss just laughs at it, crazy fool.

Anyway, thanks for all the help!
 
Glad it works. It won't be particularly slow, just IE only.

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top