View Single Post
 
Old September 27th, 2006, 03:45 AM
asearle asearle is offline
Authorized User
 
Join Date: Sep 2006
Location: Cologne, , Germany.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I understand the problem now: my javascript can accept and process entries found in the main XML file (i.e. the XML file calling the XSL) but if (anywhere in the XSL) I declare an external source (document($myparam) or document(myfile.xml)), then the content of the external file will be displayed but the script stops working. I assume that data from external XMLs can only be retrieved once?

Or is there a method to 'requery' the whole thing.

Anyway, here is my complete code. It displays the list of files OK and displays the content of the default declared file (file2.xml) but will not flip to display the contents of file1.

If I remove the declaration 'document($srce)' (and all associated code) then the selection works fine but of course there is no data to display.

I do hope you can help me with this one?

-- filelist.xml --
<?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>