WordPress.org

Ready to get started?Download WordPress

Forums

Need help toggling multiple XSL style sheets (2 posts)

  1. tunghoy
    Member
    Posted 4 years ago #

    In one of my template pages, I'm using PHP to load an XML doc and transform it with XSL. It displays in a Div just fine.

    My question is: I want to switch among multiple XSL files that transform this same XML doc. The idea is to let the user click a link that loads the appropriate XSL (to display the data in different ways). I was doing this easily when loading the XML with client-side AJAX, but with PHP, the XML is already rendered when the page loads. It's not dynamic.

    I can probably use JavaScript to toggle visibility of multiple Divs, but that seems too processor-intensive. Any ideas?

    Here's my PHP that works:

    <?php
    $processor = new XSLTProcessor;
    
    $xsl = new DOMDocument;
    
    $current_dir = get_bloginfo('template_directory');
    $xsl -> load($current_dir . '/xml/myStyles.xsl');
    $processor -> importStyleSheet($xsl);
    
    $xml = new DOMDocument;
    $xml -> load($current_dir . '/xml/myData.xml');
    $result = $processor -> transformToXML($xml);
    
    echo "$result";
    ?>
  2. tunghoy
    Member
    Posted 4 years ago #

    In case anyone else is following this......I've achieved the effect I was looking for using tabbed panels (using the Spry panels in Dreamweaver, but I suppose jQuery or other panels will work, also). Each panel uses the same code I posted above, except they each call a different XSL file.

    But still: if anyone has a better idea, please speak up.

Topic Closed

This topic has been closed to new replies.

About this Topic