Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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 September 27th, 2006, 05:41 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

> I'm not sure what you mean by "selectable". Do you mean, selectable
> by the user when the resulting HTML is displayed in a browser?

I mean that, when I run actions (filtering, sorting, etc.) on a XSL template based on the XML file which called that XSL, then my Javascript runs fine: The user is offered a listbox (generated from the underlying XML), can click on (select) an entry and the screen will display the data that has been requested.

I now find that although I can incorporate external XML files (which also display correctly), my javascript code refuses to operate. i.e. The user can see the selection that I have offered (in the list box) but he can't select anything (i.e. the javascript is inactive).

My assumption is that the underlying XML data is loaded at the time the sheet is opened and operations can be carried out on that data but not on data obtained with Document(myfile.xml). Is this true? Or am I barking up the wrong tree?

> In
> that case, you're generating the wrong HTML and we need to know
> what wrong HTML you are generating. You need to study the "source"
> of the generated HTML, it's not enough to see how it behaves in a
> browser.

I'm not sure this is the problem: All the data I require can be displayed (no problem) but the javascript which should (and in other cases does) change the selection and/or display becomes inactive.

But I'd be interested to know how to view the underlying HTML: At the moment when I click 'view source' I only get the underlying XML file.

Basically what I need to do is simply to switch the data behind a form: For example the user opens the XSL template and data from file1.xml is displayed. Then he clicks on a listbox and the display switches to file2.xml or file3.xml.

I have tried with Document('file3.xml') which displays fine once (on open) but seems to 'neutralise' my javascript and so I can't switch to file2.xml.

Maybe someone has a little example of how this can be done?

That would really help me (and it must be something that is required quite often?).

Many thanks and I really do apologise for pestering so much: But when I get it working, I will post a simple example for everyone to look at.

Regards,
Alan Searle.

 
Old September 27th, 2006, 07:04 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You don't seem to have a clear picture of the processing model.

You run an XSLT transformation to convert an XML document into an HTML document. If the user can't perform certain actions, then it's because the HTML that you have generated is wrong. You need to look at the HTML and find out what is wrong with it. The HTML doesn't "remember" how it was generated.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 27th, 2006, 07:34 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

> You don't seem to have a clear picture of the processing model.

Maybe you're right and I am thinking too sequentially. But I am truly stumped here: I can't understand why everything displays correctly and returns a correct debug in the form of:

<xsl:value-of select="$srce" /> (i.e. displaying the variable value)

... until I introduce my external XML:

<xsl:apply-templates select="document($srce)" mode="disp" />

Indeed, the external file also displays correctly (using the defaulted parameter value) but refuses to change when my javascript should change the parameter $srce.

> You need to look at the HTML and find out what is wrong with it.
> The HTML doesn't "remember" how it was generated.

This is probably a stupid question but how do I view the HTML? Can I spool it off somewhere? All I can see is the base XML.

Maybe at this stage all I need is an example: Just a snippet of code where an XSL template switches its (XML) source dynamically (i.e. switching its source from file1.xml to file2.xml). Then I believe I could work it all out.

Many, many thanks for your patience.

Regards,
Alan Searle.

 
Old September 27th, 2006, 09:28 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Indeed, the external file also displays correctly (using the defaulted parameter value) but refuses to change when my javascript should change the parameter $srce.

Where is your Javascript? In the generated HTML page itself? If so, it's executing long after the XSLT transformation has completed.

How are you actually firing off the transformation and supplying parameters to it?

>This is probably a stupid question but how do I view the HTML?

It sounds as if you are doing your development entirely in the browser, which is about the worst possible debugging environment. I'd recommend not going anywhere near a browser until you are confident that you're generating good HTML. Either develop using a text editor and the command line, or using a tool such as Stylus Studio or XML Spy.

If you're using IE there is a plug-in utility that allows you to view the HTML generated as the output of the transformation. The bad news is I can't find it right now.


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 27th, 2006, 10:24 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hallo Michael,

Thanks for taking time for this. It's much appreciated.

> Where is your Javascript? In the generated HTML page itself? If so,
> it's executing long after the XSLT transformation has completed.

I dropped a copy of the XSL (and the XML files that it should be switching between) at the end of this posting. The javascript is located in the <HEAD> of the HTML. The XSL is called from filelist.xml.

> How are you actually firing off the transformation and supplying
> parameters to it?

I have a button fed by a picklist (<SELECT>) ...

<input type="button" value="ausführen" onClick="procss(document.formfilt.selsrce.value)"/>

... which is tested thus ...

<xsl:choose>
 <xsl:when test="$srce">

It works fine when the source is not external (i.e. Document($srce) )

I'll following up your suggestions about avoiding debugging with the browser.

It would be great if you could take a quick peep at my code (below) but make sure that you don't let yourself get bogged down!

Here I am surprised that I couldn't trawl up a simple example showing me how to switch XML sources dynamically. Isn't it done? Maybe it is not part of the philosophy? As it is, my reason for wanting to do it is to allow me to break up big (15Mb+) XML files that I need to produce.

Many thanks for your help.

Regards,
Alan Searle

PS: Below is my code (it works OK when open it and the javascript works too when you comment out the call to Document($srce) ) ...

-- filelist.xml -- (initiates the whole thing ...)
<?xml-stylesheet href="data.xsl" type="text/xsl"?>
<?xml version="1.0" encoding="UTF-8"?>
<files>
  <file>file1.xml</file>
  <file>file2.xml</file>
</files>

-- file1.xml --
<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
  <item>1A</item>
  <item>1B</item>
  <item>1C</item>
</dataroot>

-- file2.xml --
<?xml version="1.0" encoding="UTF-8"?>
<dataroot>
  <item>2A</item>
  <item>2B</item>
  <item>2C</item>
</dataroot>

-- data.xsl --
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="srce" select="'file2.xml'" />

<xsl:template match="/">

<html>
<head>

<script language="javascript" type="text/javascript">

function procss(srce){
try{
  var s = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
  var x = document.XMLDocument;
  if (x == null){
   x = navigator.XMLDocument;
   s.loadXML(navigator.XSLDocument.xml);
  }else{
   s.loadXML(document.XSLDocument.xml);
  }
  var tem = new ActiveXObject("MSXML2.XSLTemplate");
  tem.stylesheet = s;
  var proc = tem.createProcessor();
  proc.addParameter("srce", srce);
  proc.input = x;
  proc.transform();
  var str = proc.output;

  var newDoc = document.open("text/html");
  newDoc.write(str);
  navigator.XMLDocument = x;
  navigator.XSLDocument = s;
  newDoc.close();
 }
 catch(exception){
 }
}

</script>
</head>

<body>

   <form name="formfilt" id="formfilt">

     <label for="selsrce">Source</label><br />

     <select size="5" name="selsrce" id="selsrce">
       <xsl:apply-templates select="files" mode="fl">
       <xsl:sort order="descending"/>
       </xsl:apply-templates>
     </select>

    <input type="button" value="ausführen" onClick="procss(document.formfilt.selsrce.value)"/>
   </form>

<xsl:choose>
 <xsl:when test="$srce">

      <xsl:value-of select="$srce" />
      <table>
      <xsl:apply-templates select="document($srce)" mode="disp">
      </xsl:apply-templates>
     </table>

 </xsl:when>
</xsl:choose>

</body>
</html>

</xsl:template>

<xsl:template match="/dataroot/item" mode="disp">
  <tr><td>
  <xsl:value-of select="."/>
  </td></tr>
</xsl:template>

<xsl:template match="files/file" mode="fl">
  <option value="{.}"><xsl:value-of select="."/></option>
</xsl:template>

</xsl:stylesheet>


 
Old September 27th, 2006, 11:51 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm afraid I don't have time to take this any further. You seem to be invoking an initial transformation using <?xml-stylesheet?>, and then doing further transformations invoked from the Javascript within the HTML page, but using the same stylesheet. It's hard to keep a clear head when following this through, and I actually have very little experience of doing anything this complex within IE. Also, this kind of structure is so dependent on the browser environment that it's hard to develop it freestanding. Good luck.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old September 28th, 2006, 01:22 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

> I'm afraid I don't have time to take this any further.

No problem: I understand ... and thanks for your feedback and your time!

I have decided to solve the problem another way: I will have an entry screen where the data is divided into periods (200609, 200608, 200607, 2006Q2, 2006Q1, 2006, etc.) and the user will first have to select the period. That will take him on to the main XSL form and will mean that the XML will be (relatively) small (about 2Mb) and that the XSL/javascript won't need to do any file switching.

The moral of the story is that sometimes an organisational/ergonomic fix can be better than a technical one :-)

Once again many thanks and do keep up the good work with this forum!

Regards,
Alan.

My email is: asearle .x.x. at .x.x. alse.com

 
Old September 28th, 2006, 02:32 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I will try to reproduce your problem later today but one thing that strikes me is you are using document.write which overwrites all existing HTML.
Why not just create a new select based on the chosen file and replace the existing one? Why do you need to change the whole document each time?

If I've got this wrong please state your requirements in simple steps, e.g.
 
  • Create an HTMl file based on XML with linked XSLT
  • User choose appropriate XML
  • New select box constructed based on values in XML



--

Joe (Microsoft MVP - XML)
 
Old October 4th, 2006, 02:46 AM
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe,

> I will try to reproduce your problem later today

Thanks. It would be great if you could check it out.

> but one thing that strikes me is you are using document.write which
> overwrites all existing HTML.
> Why not just create a new select based on the chosen file and
> replace the existing one? Why do you need to change the whole
> document each time?

Ah-ha: Maybe I am using the wrong approach here?

> If I've got this wrong please state your requirements in simple
> steps, e.g.
> - Create an HTML file based on XML with linked XSLT
> - User choose appropriate XML
> - New select box constructed based on values in XML

So far, I have only used XSL triggered by an entry in the XML header. And yes, I imagine it would be much easier to have an HTML file which calls/links the appropriate XML files and XSL templates.

Do you know of a good tutorial URL with a couple of examples of this? That might solve this and several other issues in one go.

Many thanks,
Alan Searle.





Similar Threads
Thread Thread Starter Forum Replies Last Post
parameterized if-then not working hoqenishy XSLT 1 April 17th, 2008 01:25 PM
Parameterized Property surendraparashar C# 2005 4 October 17th, 2007 11:33 PM
Parameterized Query asters VB.NET 2002/2003 Basics 5 July 9th, 2007 12:08 PM
Parameterized SQLDataAdapter boyshey VB.NET 2002/2003 Basics 1 April 14th, 2006 07:08 AM
Parameterized OracleDataCommand narendra_patil BOOK: Beginning ASP.NET 1.0 0 April 21st, 2005 05:17 AM





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