Re: colored sample code?
| From: | Christian Weiske | Date: | Tue, 03 Aug 2004 06:15:07 +0000 |
| Subject: | Re: colored sample code? | ||
| References: | 1 | Groups: | php.gtk.doc |
| Request: | Send a blank email to php-gtk-doc+get-1059@lists.php.net to get a copy of this message | ||
Hi
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
enable ext/xsl and it will magically appear dumb one... and I checked my php 4.3.6...I compiled my php5.0.0 with xsl support and created an xml with some programlistings: ================= <colorcodetest> <programlisting role="C"> <![CDATA[ static char * <pixmap name>[] = { "Pixel-strings" };]]> </programlisting> <programlisting> <![CDATA[ list( $pixmap, $mask) = gdk::pixmap_create_from_xpm_d( $objWindow->window, $colTransparent, $arImage); ]]> </programlisting> <programlisting role="php"> <![CDATA[ $colTransparent = &new GdkColor(0, 0, 0);]]> </programlisting> <programlisting role="php"> <![CDATA[ <?php if( !extension_loaded('gtk')) { dl( 'php_gtk.' . PHP_SHLIB_SUFFIX); } ]]></programlisting> </colorcodetest> ================= Now I created an XSL which calls my php function: ================= <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"xsl:extension-element-prefixes="php" version='1.0'> <xsl:output method="html" encoding="utf-8" indent="no" /> <xsl:template match="programlisting"> <xsl:choose> <xsl:when test="@role = 'php'">
<xsl:variable name="code"><xsl:value-of select="."/> </xsl:variable> <!--
<xsl:value-of select="php:function('colorCode', @role, $code)" />
-->
<xsl:value-of select="php:function('colorCode', @role, node())" />
</xsl:when>
<xsl:otherwise>
nocolor <xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
=================
And now my php:
===============
<?php
if (!extension_loaded('xsl'))
die('xsl extension not available');
error_reporting(E_ALL | E_NOTICE);
/**
* Colors a given DOM programlisting node
* only if the role is php
*
<xsl:template match="programlisting">
<xsl:value-of select="php:function('colorCode', @role, node())" />
</xsl:template>
*
* @param daRole The role attribute
* @param deCode The programlisting node
*/
function colorCode( $daRole, $deCode) {
if( $daRole[0]->value != 'php') {
return $deCode;
}
var_dump( $deCode);
if( is_array( $deCode)) {
foreach( $deCode as $obj) {
var_dump( $obj);
if( $obj instanceof DOMCdataSection) {
var_dump( $obj->value);
var_dump( $obj->node_value);
var_dump( $obj->content);
}
}
}
return "blu";
}
$xml = new DomDocument();
$xml->load('example.xml');
$xsl = new DomDocument();
$xsl->load( 'example.xsl');
$proc = new xsltprocessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet( $xsl);
echo $proc->transformToXML( $xml);
?>
===============
If you test it you will see, that the function colorCode is called.
The second parameter is an array with domtext and domcdatasection in it. Now, what I do, there is no way to get the content of the cdata section. That's the problem - if this was solved, we'd have colored code in the manual.
As I don't get the content of the cdatasection, I tried to make a variable with the contents of the programlisting and pass this to the php function (see the commented line in the xsl). Now:
php:function object type 9 is not supported yetIt seems we have to wait until the xsl extension has grown more. Or run a script on all html files after. Regards/MfG, Christian Weiske -- XMMS is playing now: Christina Aguilera - Infatuation
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc