3

Errors:

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
Undefined variable in /transform.php on line 24

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
compilation error: file /protocols.xsl line 18 element template in /transform.php on line 24

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
Failed to compile predicate in /transform.php on line 24

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
Undefined variable in /transform.php on line 24

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
compilation error: file /home6/oneninfi/public_html/craigfreeman/iphone/project1/protocols.xsl line 22 element template in /transform.php on line 24

Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: 
Failed to compile predicate in /transform.php on line 24

Warning: XSLTProcessor::transformToXml() [xsltprocessor.transformtoxml]: 
No stylesheet associated to this object in /transform.php on line 35

PHP:

$xsl = new XSLTProcessor();
    $xsldoc = new DOMDocument();
    $xsldoc->load($_GET['xsl'].'.xsl'); // protocols.xsl
    $xsl->importStyleSheet($xsldoc); // LINE 24

    if(isset($_GET['sectionNumber']))
        $xsl->setParameter('', 'sectionNumber', $_GET['sectionNumber']);
    if(isset($_GET['protocolNumber']))
        $xsl->setParameter('', 'protocolNumber', $_GET['protocolNumber']);
    if(isset($_GET['entryNumber']))
        $xsl->setParameter('', 'entryNumber', $_GET['entryNumber']);

    $xmldoc = new DOMDocument();
    $xmldoc->load($_GET['xml'].'.xml');
    echo $xsl->transformToXML($xmldoc); // LINE 35

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="protocolNumber"></xsl:param>
    <xsl:param name="sectionNumber"></xsl:param>
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="page/section[@id=$sectionNumber]"> // LINE 18
    <xsl:apply-templates select="protocol[@id=$protocolNumber]"/>
</xsl:template>

<xsl:template match="protocol[@id=$protocolNumber]"> // LINE 22
  <h4>(<xsl:value-of select="$sectionNumber"/>.<xsl:value-of select="@id"/>)&nbsp;<xsl:value-of select="@title"/></h4>
    <!-- Applies templates to all child elements -->
    <ol><xsl:apply-templates/></ol>
</xsl:template>

<xsl:template match="start">
  <span class="start"><xsl:value-of select="@level" /></span>
</xsl:template>

<xsl:template match="stop">
  <span class="stop"><xsl:value-of select="@level" />&nbsp;STOP</span>
</xsl:template>

<xsl:template match="note">
  <span class="note"><span class="noteType"><xsl:value-of select="@title" /></span>:&nbsp;<xsl:value-of select="." /></span>
</xsl:template>

<xsl:template match="step">
   <li><span class="step"><xsl:value-of select="."/></span></li>
</xsl:template>

</xsl:stylesheet>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<page type="Protocols">
    <section id="3" title="Adult Cardiac Life Support">
        <protocol id="0" title="Cardiac Arrest - General Procedures">
            <start level="All Levels"/>
                <step>Verify patient is pulseless and apneic.</step>
                <step>Initiate or continue CPR.  CPR is to be continued at all times, except during defibrillation and /or interruptions &lt; 10 sec for patient transfer.</step>
                <step>Assure airway patency and begin use of BVM.  Provide initial BLS airway management, including Oropharyngeal or Nasopharyngeal Airway.</step>
                <step>Apply AED or SAED if available.  If AED already in place, wait until current shock sequence completion to switch to another AED or manual monitor – may use previously applied patches if compatible with new unit.</step>
                <step>Follow prompts provided by AED/SAED device.</step>
                <step>Utilize ALS, or initiate timely transport toward ALS (ALS intercept or hospital if closer).  If ALS not available, no more than 3 shocks should be delivered at the scene.  Defibrillation should not be performed in a moving ambulance.</step>
                <step>Advise receiving hospital ASAP.</step>
            <stop level="EMT"/>
            <start level="EMT-I, CC &amp; P"/>
                <step>If AED/SAED not already applied, quick look using manual monitor and defibrillate PRN after CPR of at least 5 cycles (about 2 minutes).  Apply limb leads and pads in between shock sequences as appropriate.</step>
                <step>Obtain vascular access.</step>
                <step>Secure definitive airway.  If BLS airway is sufficient to maintain chest rise, continue until additional time or resources are available.  If unable to intubate, continue use of BLS airway adjuncts or use alternate airway device.<br/><br/>emove Bag Valve device whenever transferring patient, moving patient in and out of Ambulance, or other times 
when Bag Valve device may dislodge the device.<br/><br/>Reassess airway patency after any movement of patient.</step>
            <stop level="EMT-I" />
            <start level="EMT-CC &amp; P"/>
                <step>Give medications as listed in the following specific arrhythmia / dysrhythmia protocols. 
</step>
                <note title="NOTE">Should IV/IO access not be available, Epinephrine, Atropine, and Lidocaine may be administered via ETT under 
direct, on-line Medical Control.</note>
        </protocol></section></page>

PHP5 XML/XSL enabled

Thoughts? Anything obvious??

Tomalak
  • 332,285
  • 67
  • 532
  • 628
cfree
  • 333
  • 5
  • 15

7 Answers7

2

One possibility is that the XSL processor is really complaining about &nbsp; not being declared as an entity. Try changing the doctype to

<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp '&#160;'> ] >
Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • Good catch! It actually already is, I just cut it out to post here. I won't do that next time... – cfree Nov 10 '09 at 21:26
  • If that wasn't it, then I suspect a bug. I loaded your xsl verbatim into Oxygen/XML and the missing entity was the only problem. After fixing that it passes well-formedness tests. – Jim Garrison Nov 10 '09 at 21:41
  • I meant a bug in XSLTProcessor.importStyleSheet(), of course. – Jim Garrison Nov 10 '09 at 21:42
  • Thanks for checking. Yes, it's something to do with how the XSL processes in PHP. I think it doesn't like attribute comparison testing (ie: node[@id=$parameter]) – cfree Nov 11 '09 at 18:36
2

Your stylesheet is not valid XSLT 1.0: you cannot have a variable/parameter reference in a pattern

You can use variable/parameter reference in XSLT 2.0 patterns.

As suggested by @abc you need to pass that test inside the content template.

Community
  • 1
  • 1
  • A couple years ago, the version of libxml our developers were using allowed variables in the match attribute, but QA was using a newer environment that failed. Trying to figure that one out remotely was fun. – grantwparks Feb 13 '12 at 10:18
1

Look at this error: Warning: XSLTProcessor::importStylesheet() [xsltprocessor.importstylesheet]: compilation error: file /protocols.xsl line 18 element template in /transform.php on line 24

On line 18 you have:

<xsl:template match="page/section[@id=$sectionNumber]"> // LINE 18

Where is $sectionNumber defined? PHP cannot see it.

Alexandru Luchian
  • 2,760
  • 3
  • 29
  • 41
  • sets the sectionNumber parameter in the XSL passed in from the PHP $xsl->setParameter('', 'sectionNumber', $_GET['sectionNumber']);. It is accessed elsewhere in the XSL document by calling $sectionNumber – cfree Nov 10 '09 at 21:19
  • Well, anyway, it's not seeing this parameter. That's why the error it says: Undefined variable in /transform.php on line 24 – Alexandru Luchian Nov 10 '09 at 21:28
  • I agree with you, though I think it's a result of the stylesheet not being imported for whatever reason. – cfree Nov 10 '09 at 21:31
  • I was able to reproduce the problem on my computer. I just didn't pass any variable/parameter. The stylesheet is not imported because the $variables get resolved to null so it's an error in the stylesheet. – Alexandru Luchian Nov 10 '09 at 21:59
  • It can't be an error, the XSL validates and displays fine using Javascript... I tried manually setting the variables inside the XSL (and not passing any variables in through PHP) and I get the same errors. – cfree Nov 10 '09 at 22:35
  • Youre right about the variables, though. They weren't being tested against inside the XSL. Whatever the problem is, the workaround was to pass the variables in using GET variables and set them inside a PHP file that echos out the XSL with a header of "text/xml." – cfree Nov 11 '09 at 18:39
  • @Alexandru Luchian: Check my answer for an exact explantion of the problem. –  Nov 25 '10 at 22:15
1

i've experienced the same issue, seems to be an issue in XSLTProcessor if you call an XSL with a parameter, define the parameter on `

<template match="/"><xsl:parameter name="whatever"/">

then you can call xslt->setParameter, it gives errors in the apache log, but it seems to work!

Curtis
  • 101,612
  • 66
  • 270
  • 352
JS.
  • 11
  • 1
1

Same problem here. I worked around it by enclosing 'xsl:if' nodes in the 'xsl:template' nodes. In your case, it'd give:

<xsl:template match="page/section"> // LINE 18
    <xsl:if test="@id=$sectionNumber">
        <xsl:apply-templates select="protocol[@id=$protocolNumber]"/>
    </xsl:if>
</xsl:template>

<xsl:template match="protocol"> // LINE 22
    <xsl:if test="@id=$protocolNumber">
        <h4>(<xsl:value-of select="$sectionNumber"/>.<xsl:value-of select="@id"/>)&nbsp;<xsl:value-of select="@title"/></h4>
        <!-- Applies templates to all child elements -->
        <ol><xsl:apply-templates/></ol>
    </xsl:if>
</xsl:template>
abc
  • 11
  • 1
0

Looks to me that $_GET['xsl'] is empty.

Alexandru Luchian
  • 2,760
  • 3
  • 29
  • 41
  • It isn't. When I replaced the variable with 'protocols.xsl' and 'http://www.domain.com/protocols.xsl' I got the same errors... – cfree Nov 10 '09 at 20:46
0

Your xsl has an error in it. When you load it into the XSLTProcessor object, it fails. Therefore you can't apply it the the xml.

dnagirl
  • 20,196
  • 13
  • 80
  • 123
  • I don't think so. I don't get any errors when viewing the xsl file directly in a browser and I can get the xsl to transform the xml using Javascript (won't work in all clients, ie the PHP attempt). – cfree Nov 10 '09 at 20:57