hholzgra Thu Jan 17 05:15:35 2002 EDT
Added files:
/phpdoc/scripts/apply func2methodsyn.php
Log:
conversion script for docbook4 upgrade
will convert <funcsynopsis> to <methodsynopsis>
which has better support for optional paramters
(attribute instead of extra tag)
the way we use currently use <optional> in
funcsynopsis is not compatible with docbook4 dtd :(
so we have to do this conversion when we switch
but the documentation support for object-oriented
stuff in docbook4 will be worth the effort
do not apply unless all other needed components
and changes are in place
Index: phpdoc/scripts/apply/func2methodsyn.php
+++ phpdoc/scripts/apply/func2methodsyn.php
<?php
$conversion_xsl='
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" />
<!-- default rule -> copy element, attributes and recursive content -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- ignore funcsynopsis tags -->
<xsl:template match="/funcsynopsis">
<xsl:apply-templates/>
</xsl:template>
<!-- convert foncprototype to methodsynopsis -->
<xsl:template match="/funcsynopsis/funcprototype">
<methodsynopsis>
<xsl:apply-templates/>
</methodsynopsis>
</xsl:template>
<!-- ignore funcdef tag -->
<xsl:template match="/funcsynopsis/funcprototype/funcdef">
<xsl:apply-templates/>
</xsl:template>
<!-- function is now methodname in this context -->
<xsl:template match="/funcsynopsis/funcprototype/funcdef/function">
<methodname><xsl:apply-templates/></methodname>
</xsl:template>
<!-- replaceable is now methodname.replaceable in this context -->
<xsl:template match="/funcsynopsis/funcprototype/funcdef/replaceable">
<methodname><replaceable><xsl:apply-templates/></replaceable></methodname>
</xsl:template>
<!-- first text element is the return type
needs to be enclosed in type tags now
-->
<xsl:template match="/funcsynopsis/funcprototype/funcdef/text()[1]">
<xsl:if test="position() = 1"> <!-- first only -->
<type>
<xsl:value-of select="normalize-space(.)"/>
</type>
</xsl:if>
</xsl:template>
<!-- paramdef is now methodparam, empty paramdef should be void/ -->
<xsl:template match="/funcsynopsis/funcprototype/paramdef">
<xsl:choose>
<xsl:when test="count(parameter)>0">
<methodparam>
<xsl:if test="*/optional"> <!-- optional is now attribute and not special tag -->
<xsl:attribute name="choice">opt</xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</methodparam>
</xsl:when>
<xsl:otherwise>
<void/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- first text in paramdef is paramter type and needs type tags -->
<xsl:template match="/funcsynopsis/funcprototype/paramdef/text()[1]">
<xsl:if test="position() = 1">
<type>
<xsl:value-of select="normalize-space(.)"/>
</type>
</xsl:if>
</xsl:template>
<!-- ignore optional tag here, already processed above -->
<xsl:template match="/funcsynopsis/funcprototype/paramdef/parameter/optional">
<xsl:apply-templates/>
</xsl:template>
<!-- there is no varargs in methodsynopsis, but a rep attribute for methodparam -->
<xsl:template match="/funcsynopsis/funcprototype/varargs">
<methodparam
rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
</xsl:template>
</xsl:stylesheet>
';
function apply($input) {
global $conversion_xsl;
$output="";
if(!function_exists("xslt_create")) {
die("this conversion requires a PHP executable with XSLT extension");
}
$xslt = xslt_create();
$xmlhead="<?xml version='1.0' encoding='iso-8859-1' ?>\n";
$lines = explode("\n",$input);
for($nr=0;$nr<sizeof($lines);$nr++) {
$line = $lines[$nr]."\n";
if(strstr($line,("<funcsynopsis>"))) {
$funcsyn = str_replace("&","&",$line);
do {
$line=$lines[++$nr]."\n";;
$funcsyn .= str_replace("&","&",$line);
} while(!strstr($line,("</funcsynopsis>")));
$arguments = array('/_xml' => $funcsyn,
'/_xsl' => $conversion_xsl
);
$result = xslt_process($xslt, 'arg:/_xml', 'arg:/_xsl', NULL,
$arguments);
$result = str_replace("&","&",$result);
$result = explode("\n",$result);
unset($result[0]);
$output .= rtrim(join("\n",$result))."\n";
} else if (strstr($line,("<?xml"))&&($nr==1)) {
$xmlhead=$line;
$output .= $line;
} else{
$output .= $line;
}
}
xslt_free($xslt);
return $output;
}
?>