Results 1 to 2 of 2

Thread: Passing External Values To Variables In An XSL Stylesheet

  1. #1
    Join Date
    Feb 2004
    Location
    11th Dimension
    Posts
    270

    Passing External Values To Variables In An XSL Stylesheet

    Evening all,

    Lately I've been trying to figure out how to pass external values into XSLT stylesheet variables. Is this even possible?

    From what I've read about XSLT variables, they're not 'variables' in the traditional sense of the word, as once their value has been defined it can't be changed, but there must still be some use for them.

    Basically, I need to pass the value of a drop-down menu on an HTML form into a variable in an XSLT stylesheet. I've been reading up on it for days and come up blank. Any thoughts?

    Thanks for your help.

    - Streak

    Natalie Portman Addict

  2. #2
    Join Date
    Feb 2004
    Location
    11th Dimension
    Posts
    270
    Well I guess I didn't make a whole lot of sense there, but I think I've found the basic script that does the job. For anyone that's interested:

    Code:
    <?php
    
    // XML string
    $xml = '<?xml version="1.0"?>
    <para>
     change me
    </para>';
    
    // XSL string
    $xsl = '
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="ISO-8859-1" indent="no"
     omit-xml-declaration="yes"  media-type="text/html"/>
     <xsl:param name="myvar"/>
     <xsl:param name="mynode"/>
     <xsl:template match="/">
    My PHP variable : <xsl:value-of select="$myvar"/><br />
    My node set : <xsl:value-of select="$mynode"/>
     </xsl:template>
    </xsl:stylesheet>';
    
    
    $xh = xslt_create();
    
    // the second parameter will be interpreted as a string
    $parameters = array (
      'myvar' => 'test',
      'mynode' => '<foo>bar</foo>'
    );
    
    $arguments = array (
      '/_xml' => $xml,
      '/_xsl' => $xsl
    );
    
    echo xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments, $parameters);
    
    ?>
    Natalie Portman Addict

Similar Threads

  1. Passing Flash Variables
    By SlayersOtaku in forum Graphic Design
    Replies: 1
    Last Post: 20 Mar 2010, 04:02 PM
  2. Passing JS Variables From HTML to a .JS file
    By DankaShine in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 21 Jul 2005, 05:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •