Error in the XSL + XSD + XML + PHP Process

Viewed 57

So i've got to a frustratingly close point in my project and hoping some XMl guru can point out the error in my ways!

I am generating an XML from an XSD to be used with a XSL into a PHP update tool that generates a new xml. I am most of the way there.

The tool:

<?php
function loadFile($xml, $xsl)
{
$xmlDoc = new DOMDocument();
$xmlDoc->load($xml);

$xslDoc = new DOMDocument();
$xslDoc->load($xsl);

$proc = new XSLTProcessor();
$proc->importStyleSheet($xslDoc);
echo $proc->transformToXML($xmlDoc);
}

function updateFile($xml)
{
$xmlLoad = simplexml_load_file($xml);
$postKeys = array_keys($_POST);

foreach($xmlLoad->children() as $x)
{
  foreach($_POST as $key=>$value)
  {
    if($key == $x->attributes())
    {
      $x->value = $value;
    }
  }
}

$xmlLoad->asXML($xml);
loadFile($xml,"tool_updated.xsl");
}

if($_POST["btn_sub"] == "")
{
  loadFile("TotalTaxSchedule.xml", "TotalTaxSchedule.xsl");
}
else
{
  updateFile("TotalTaxSchedule.xml");
}
?>

The tool has worked for dummy data at a small scale this is my larger implementation. the xsl:

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

-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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

<xsl:strip-space elements="*"/>

<xsl:include href="PopulateTemplate.xsl"/>

<xsl:include href="AddHeader.xsl"/>

<xsl:include href="CommonPathRef.xsl"/>

<xsl:include href="AddOnTable.xsl"/>

<xsl:param select="$RtnDoc/TotalTaxSchedule" name="TTSData"/>

<!-- 1120 Common - Total Tax Schedule -->



-<xsl:template name="ShowTTS">


-<table class="styDepTblLandscape" id="TTSTbl">


-<thead class="styTableThead">


-<tr class="styDepTblHdr">

<th class="styDepTblCell" style="width:47mm;" scope="col">Corporation Name</th>

<th class="styDepTblCell" style="width:32mm;" scope="col">Corporation EIN</th>

<th class="styDepTblCell" style="width:67mm;" scope="col">Computation </th>

<th class="styDepTblCell" style="width:37mm;" scope="col">Code Section </th>

<th class="styDepTblCell" style="width:37mm;" scope="col">Type of Tax </th>

<th class="styDepTblCell" style="width:36mm;" scope="col">Amount of Tax </th>

</tr>

</thead>

<tfoot/>


-<tbody>


-<xsl:for-each select="$TTSData/TotalTaxInformationGrp">


-<tr>


-<xsl:attribute name="class">


-<xsl:choose>

<xsl:when test="position() mod 2 = 1">styDepTblRow1</xsl:when>

<xsl:otherwise>styDepTblRow2</xsl:otherwise>

</xsl:choose>

</xsl:attribute>


-<td class="styDepTblCell" style="text-align:left;width:47mm;">


-<xsl:call-template name="PopulateText">

<xsl:with-param select="CorporationName/BusinessNameLine1Txt" name="TargetNode"/>

</xsl:call-template>


-<xsl:if test="CorporationName/BusinessNameLine2Txt != ''">

<br/>


-<xsl:call-template name="PopulateText">

<xsl:with-param select="CorporationName/BusinessNameLine2Txt" name="TargetNode"/>

</xsl:call-template>

</xsl:if>

</td>


-<td class="styDepTblCell" style="text-align:center;width:32mm;">


-<xsl:if test="CorporationEIN">


-<xsl:call-template name="PopulateEIN">

<xsl:with-param select="CorporationEIN" name="TargetNode"/>

</xsl:call-template>

</xsl:if>


-<xsl:if test="MissingEINReasonCd">


-<xsl:call-template name="PopulateText">

<xsl:with-param select="MissingEINReasonCd" name="TargetNode"/>

</xsl:call-template>

</xsl:if>

</td>


-<td class="styDepTblCell" style="text-align:left;width:67mm;">


-<xsl:call-template name="PopulateText">

<xsl:with-param select="ComputationDesc" name="TargetNode"/>

</xsl:call-template>

</td>


-<td class="styDepTblCell" style="text-align:left;width:37mm;">


-<xsl:call-template name="PopulateText">

<xsl:with-param select="CodeSectionTxt" name="TargetNode"/>

</xsl:call-template>

</td>


-<td class="styDepTblCell" style="text-align:left;width:37mm;">


-<xsl:call-template name="PopulateText">

<xsl:with-param select="TaxOrInterestTypeDesc" name="TargetNode"/>

</xsl:call-template>

</td>


-<td class="styDepTblCell" style="text-align:right;width:36mm;" nowrap="yes">


-<xsl:call-template name="PopulateAmount">

<xsl:with-param select="TaxAmt" name="TargetNode"/>

</xsl:call-template>

</td>

</tr>

</xsl:for-each>

</tbody>

</table>

</xsl:template>


-<xsl:param name="depDocTitle">


-<xsl:call-template name="PopulateDisplayName">

<xsl:with-param select="$TTSData" name="TargetNode"/>

</xsl:call-template>

</xsl:param>

<!-- Main template -->



-<xsl:template match="/">

<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>


-<html>


-<head>

<meta content="IE=edge" http-equiv="X-UA-Compatible"/>


-<title>

<xsl:value-of select="$depDocTitle"/>

</title>

<!-- No Browser Caching -->


<meta content="no-cache" http-equiv="Pragma"/>

<meta content="no-cache" http-equiv="Cache-Control"/>

<meta content="0" http-equiv="Expires"/>

<!-- No Proxy Caching -->


<meta content="private" http-equiv="Cache-Control"/>

<!-- Define Character Set -->


<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"/>

<meta name="Author" content="Ravi Venigalla"/>

<meta name="Description" content="{$depDocTitle}"/>

<script language="JavaScript" type="text/javascript" src="{$ScriptPath}/FormDisplay.js"/>

<xsl:call-template name="InitJS"/>


-<style type="text/css">


-<xsl:if test="not($Print) or $Print=''">

<xsl:call-template name="AddOnStyle"/>

</xsl:if>

</style>

<xsl:call-template name="GlobalStylesDep"/>

</head>


-<body class="styBodyClass">

<xsl:call-template name="DocumentHeaderDependencyLandscape"/>


-<div class="styDepTitleLineLandscape ">


-<span class="styDepTitle" style="width:65mm">

<xsl:value-of select="$depDocTitle"/>

</span>

</div>

<!--Adding template for left over data -->



-<xsl:call-template name="PopulateDepCommonLeftoverLandscape">

<xsl:with-param select="$TTSData" name="TargetNode"/>

</xsl:call-template>

<xsl:call-template name="ShowTTS"/>

<br/>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

The XML:

<?xml version="1.0" encoding="utf-8"?>
<TotalTaxSchedule documentId="documentId1" softwareId="softwareId1" softwareVersionNum="softwareVersionNum1" documentName="TotalTaxSchedule" xmlns="http://www.irs.gov/efile">
  <TotalTaxInformationGrp>
    <CorporationName>
      <BusinessNameLine1Txt>BusinessNameLine1Txt1</BusinessNameLine1Txt>
      <BusinessNameLine2Txt>BusinessNameLine2Txt1</BusinessNameLine2Txt>
    </CorporationName>
    <CorporationEIN>CorporationEIN1</CorporationEIN>
    <ComputationDesc>ComputationDesc1</ComputationDesc>
    <CodeSectionTxt>CodeSectionTxt1</CodeSectionTxt>
    <TaxOrInterestTypeDesc>TaxOrInterestTypeDesc1</TaxOrInterestTypeDesc>
    <TaxAmt>1</TaxAmt>
  </TotalTaxInformationGrp>
  <TotalTaxInformationGrp>
    <CorporationName>
      <BusinessNameLine1Txt>BusinessNameLine1Txt2</BusinessNameLine1Txt>
      <BusinessNameLine2Txt>BusinessNameLine2Txt2</BusinessNameLine2Txt>
    </CorporationName>
    <CorporationEIN>CorporationEIN2</CorporationEIN>
    <ComputationDesc>ComputationDesc2</ComputationDesc>
    <CodeSectionTxt>CodeSectionTxt2</CodeSectionTxt>
    <TaxOrInterestTypeDesc>TaxOrInterestTypeDesc2</TaxOrInterestTypeDesc>
    <TaxAmt>-999999999999999</TaxAmt>
  </TotalTaxInformationGrp>
  <TotalTaxInformationGrp>
    <CorporationName>
      <BusinessNameLine1Txt>BusinessNameLine1Txt3</BusinessNameLine1Txt>
      <BusinessNameLine2Txt>BusinessNameLine2Txt3</BusinessNameLine2Txt>
    </CorporationName>
    <CorporationEIN>CorporationEIN3</CorporationEIN>
    <ComputationDesc>ComputationDesc3</ComputationDesc>
    <CodeSectionTxt>CodeSectionTxt3</CodeSectionTxt>
    <TaxOrInterestTypeDesc>TaxOrInterestTypeDesc3</TaxOrInterestTypeDesc>
    <TaxAmt>999999999999999</TaxAmt>
  </TotalTaxInformationGrp>
</TotalTaxSchedule>

The Error I am receiving in console is:

tool.php:66 Uncaught TypeError: Cannot read property 'formLoadedInFrame' of undefined at tool.php:66

I appreciate any clues! Thank you! The XML is Generated from a IRS file which also provided the XSL file perhaps my problem is related to the finer inner-workings of that?

There is a formdisplay.js I will addend The FormDisplay.js

//=========================================================
// File Name:  FormDisplay.js
//=========================================================
// History:
//
// 7/18/2005 Edited by Charles Moore - updated IMAGEPATH and HTMLPATH for Release 3.2
//=========================================================

//=========================================================
//
// Global Variables
//
//=========================================================

var IMAGEPATH = "/mef/rrdprd/common/images/";
var HTMLPATH = "/mef/rrdprd/common/htmls/";


//=========================================================
// Script Name:  toggle()
//=========================================================
// Description:  This script allows the user to switch between viewing a table in contracted form (with scroll bars)
//  or expanded form (all rows displayed on the page)
//=========================================================
// Browsers Supported:  IE 5.x, IE 5.5, IE 6.x
// Browser Tested:  IE 5.5, IE 6.0
//=========================================================
// Pararmeters:
//     containerId - the ID of the div that wraps around the table
//     imageId -  the ID of the expand/contract button image - used to track status of table (ie track
//    whether table is expanded or contracted)
//     buttonId - ID of the expand/contract button
//=========================================================

// Preload table container toggle button images
var expandImg = new Image();
expandImg.src = IMAGEPATH + "expand.gif";
var collapseImg = new Image();
collapseImg.src = IMAGEPATH + "collapse.gif";

function toggle( containerId, imageId, buttonId )
  {
   // initialize variables.
   var container = document.getElementById( containerId );
   var image = document.getElementById( imageId );
   var button = document.getElementById( buttonId );
   // check the current image to determine action.
   var isExpandable;
   if( expandImg.src == image.src )
     isExpandable = true;
   else if ( collapseImg.src == image.src )
     isExpandable = false;
   // set action according to current state.     
   if( isExpandable )
   {
    // store height
    container.setAttribute("origHeight",container.style.height);
    // expand table.
    container.style.overflowY = "visible";
    container.style.height = "auto";
    // change the image to collapse
    image.src = collapseImg.src;
   // set the button title to "Click here to collapse table", for 508.
   button.title = "Click here to collapse table";
   image.alt = "Click here to collapse table";
   }
   else if ( !isExpandable )
   {
    // collapse table.
    container.style.overflowY = "auto";
    container.style.height = container.getAttribute("origHeight");
    // change the image to expand
    image.src = expandImg.src;
    // set the button title to "Click here to expand table"
    button.title = "Click here to expand table";
    image.alt = "Click here to expand table";
   }
   // take the focus away.
   button.blur();
  }

//=========================================================
// Script Name:  dynamicHeightToggle()
//=========================================================
// Description:  This is an alternate script to toggle for tables that have rows that can vary in 
//  height. This script allows the user to switch between viewing a table in contracted form 
//  (with scroll bars) or expanded form (all rows displayed on the page). In contracted form,
//  the height of the table is determined by adding up all of the heights of the rows that are
//  being displayed.
//=========================================================
// Browsers Supported:  IE 5.x, IE 5.5, IE 6.x
// Browser Tested:  IE 6.0
//=========================================================
// Pararmeters:
//     containerId - the ID of the div that wraps around the table
//     imageId -  the ID of the expand/contract button image - used to track status of table (ie track
//    whether table is expanded or contracted)
//     buttonId - ID of the expand/contract button
//     headerRowCount - the number of rows in the header section of the table.
//     displayRowCount - the number of rows to be displayed in the table.
//=========================================================

function dynamicHeightToggle ( containerId, imageId, buttonId, headerRowCount, displayRowCount )
  {
   // initialize variables.
   var container = document.getElementById( containerId );
   var image = document.getElementById( imageId );
   var button = document.getElementById( buttonId );
   var table = container.children[0];
   // check the current image to determine action.
   var isExpandable;
   if( expandImg.src == image.src )
     isExpandable = true;
   else if ( collapseImg.src == image.src )
     isExpandable = false;
   // set action according to current state.     
   if( isExpandable )
   {
    // expand table.
    container.style.overflowY = "visible";
    container.style.height = "auto";
    // change the image to collapse
    image.src = collapseImg.src;
   // set the button title to "Click here to collapse table", for 508.
   button.title = "Click here to collapse table";
   image.alt = "Click here to collapse table";
   }
   else if ( !isExpandable )
   {
    // collapse table.
    container.style.overflowY = "auto";
    
    var endRow = parseInt(headerRowCount) + parseInt(displayRowCount);
    var containerHeight = 0;

    for (var i = 0; i < endRow; i++) {
    containerHeight += table.rows[i].clientHeight; 
    }
    container.style.height = containerHeight + "px";
    
    // change the image to expand
    image.src = expandImg.src;
    // set the button title to "Click here to expand table"
    button.title = "Click here to expand table";
    image.alt = "Click here to expand table";
   }
   // take the focus away.
   button.blur();
  }

//=========================================================
// Script Name:  setInitialDynamicTableHeight()
//=========================================================
// Description:  This script sets the initial height of a table using the dynamicHeightToggle function.
//=========================================================
// Browsers Supported:  IE 5.x, IE 5.5, IE 6.x
// Browser Tested:  IE 6.0
//=========================================================
// Pararmeters:
//     containerId - the ID of the div that wraps around the table
//     headerRowCount - the number of rows in the header section of the table.
//     displayRowCount - the number of rows to be displayed in the table.
//     setDynamicHeight - a parameter that determines whether or not to set the height to the sum total
//  heights of the first x rows, where x is the number of rows to be displayed in the table.
//=========================================================
  
function setInitialDynamicTableHeight( containerId, headerRowCount, displayRowCount, setDynamicHeight ) 
  {
    // initialize variables.
    var container = document.getElementById( containerId );
    var table = container.children[0];   
    if (setDynamicHeight == 'false') {
      container.style.overflowY = "visible";
    }
    else
    {

      var endRow = parseInt(headerRowCount) + parseInt(displayRowCount);
      var containerHeight = 0;

      for (var i = 0; i < endRow; i++) {
      containerHeight += table.rows[i].clientHeight; 
      }
      container.style.height = containerHeight + "px";
          }
   }


  /* 
  // Set the bookmark to return to
  function SetReturnBookmark( returnToElemId, titleString ) {
    top.Toolbar.returnToDocId = "1120";
    top.Toolbar.returnToElementId = returnToElemId;
    top.Toolbar.document.getElementById( "ReturnTo" ).title = "Return to " + titleString;
  }
  */
  
  /*
  function init() {
    MakeFieldsReadOnly( true );
    CreateImgObjects();
    GetTableAndContainerHeights();
    SetToggleBtnsVisibility();
    ZoomDisplay();
  }
  */

//=========================================================
// Script Name:  showAttachedDocs()
//=========================================================
function showAttachedDocs( elemId, colorSchema, docList ){
    // elemId is the id of the element that evokes this function
    // check to see if the tree is ready.
    // uncomment during integration
     if( top.ReturnTree.document.readyState != "complete" )
     {
       alert("The attached documents are not ready for review yet. Please try again later.");
       return;
     }
     
    // feature list
    var height = "dialogHeight:120px;";
    var width = "dialogWidth:300px;";
    var scroll = "scroll:auto;";
    var status = "status:no;";
    var help = "help:no;";
    var resizable = "resizable:yes;";
     
    var docIdList = docList.split(" ");
    var clrSchema = colorSchema.split(",");
    if( docIdList.length == 1 ) {
      top.ReturnTree.displayFormByDocId( docIdList[0] );
      return;
    }
    var features = height + width + scroll + status + help + resizable;
     var docNameList = top.ReturnTree.getDisplayNameByDocId(docIdList);
       if(docNameList == null){
            top.ReturnTree.refreshDocumentList(elemId, colorSchema, docList);
            return;
       }
     var displayIdList = top.ReturnTree.getDisplayIdByDocId(docIdList);            
     var docAttrObj = new Object();
      docAttrObj.IdList = docIdList;
      docAttrObj.NameList = docNameList;
      docAttrObj.DisplayIdList = displayIdList;           
      docAttrObj.Color = clrSchema;
      docAttrObj.Opener = self;
      
    // Get the x and y coordinates of the calling element, relative to document body
    xElem = 0;
    yElem = 0;
    elemObj = document.getElementById( elemId );

    while ( elemObj != document.body ) {
    xElem += elemObj.offsetLeft;
    yElem += elemObj.offsetTop;
    elemObj = elemObj.offsetParent;
    }

    // Get the x and y coordinates of the browser's document display area, relative to the screen
    xWindow = window.screenLeft;
    yWindow = window.screenTop;

    // Set the x and y coordinates of the calendar popup, relative to the screen, and substract off pixels scrolled by the document body.
    xPopup = xElem + xWindow - document.body.scrollLeft;
    yPopup = yElem + yWindow - document.body.scrollTop;

    //==================================================================
    // Note: IE aligns the right edge of the popup with the right edge of the screen if there is not enough
    //          horizontal space between the calling element and the right edge of the screen. It works in the
    //          same manner for the bottom edge except when the Windows Taskbar is set to be "Always on top"
    //          and "Auto hide" is NOT checked. In this case, the bottom portion of the popup could be covered
    //          by the Taskbar. Therefore, we need to account for the Taskbar being permanently visible.
    //==================================================================
    if ( screen.availHeight - yPopup < height )     yPopup = screen.availHeight - height;

    // popup window left position in pixels
    features  += ";dialogLeft:" + xPopup + "px";
    // popup window top position in pixels
    features  += ";dialogTop:" + yPopup + "px";
     
     window.showModalDialog( HTMLPATH + "formlist.html",docAttrObj,features);
     return;
}
// javascript dealing with left over data
var writeInId = 'PageHeader';   // this is defined in AddHeader.xsl.  It is assumed that it will be there.
function goToLeftoverDataTable( selectedWIId ) {
  writeInId = selectedWIId;
  document.getElementById( "LeftoverData" ).scrollIntoView();
  return;
}

function returnToWriteInImage() {
  document.getElementById( writeInId ).scrollIntoView();
  return;
}
0 Answers
Related