Gunnar Bittersmann: bedingte Transformation

Beitrag lesen

Hello out there!

Aber genau so sollte es sein!
Eventuell an der Zeile :$xslt_params["sort"] = $HTTP_GET_VARS["sort"]; was ändern bzw. sie überprüfen, damit du die HTTP-Variable wirklich bekommst

Die bekomme ich: http://gundi.de/test/xslt-param.php?sort=foo

$HTTP_GET_VARS["sort"]           »foo«
<xsl:value-of select="$sort"/>   »«
<xsl:value-of select="{$sort}"/>

xslt-param.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
  <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
    <title>Test: XSLT mit Parameter</title>  
    <link rel="stylesheet" type="text/css" href="xslt-param.css" />  
  </head>  
  <body>  
    <table>  
      <tr>  
        <th>$HTTP_GET_VARS["sort"]</th>  
        <td>»<?php [code lang=php]echo $HTTP_GET_VARS["sort"];
~~~ ?>«</td>  
      </tr>  
      <tr>  
        <th>&lt;xsl:value-of select=&quot;$sort&quot;/&gt;</th>  
<?php  
~~~php
  $xslt = xslt_create();  
  $xml = 'xslt-param.xml';  
  $xsl = 'xslt-param.xsl';  
  $xslt_params["sort"] = $HTTP_GET_VARS["sort"];  
  $result = xslt_process($xslt, $xml, $xsl, NULL, NULL, $params);  
  xslt_free($xslt);  
  echo $result;

?>
      </tr>
      <tr>
        <th>&lt;xsl:value-of select=&quot;{$sort}&quot;/&gt;</th>
<?php

  $xslt = xslt_create();  
  $xml = 'xslt-param.xml';  
  $xsl = 'xslt-param-braces.xsl';  
  $xslt_params["sort"] = $HTTP_GET_VARS["sort"];  
  $result = xslt_process($xslt, $xml, $xsl, NULL, NULL, $params);  
  xslt_free($xslt);  
  echo $result;

?>
      </tr>
    </table>
  </body>
</html>[/code]

xslt-param.xsl:

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

>  

  <xsl:output  
    xsl:encoding="UTF-8"  
    xsl:indent="no"  
    xsl:method="xml"  
    xsl:omit-xml-declaration="yes"  
    xsl:standalone="no"  
  />  
  <xsl:param name="sort"/>  
  <xsl:template match="/">  
    <td>  
      <xsl:text>»</xsl:text>  
      <xsl:value-of select="$sort"/>  
      <xsl:text>«</xsl:text>  
    </td>  
  </xsl:template>  
</xsl:stylesheet>

in xslt-param-braces.xsl:

<xsl:value-of select="{$sort}"/>

See ya up the road,
Gunnar

--
“Remember, in the end, nobody wins unless everybody wins.” (Bruce Springsteen)