Rewrite the id code to convert the characters of parts of the id at the time of

generating the id. This means that characters are translated to underscores for
ids as well as for filenames, since in the eventual documents they have to be
percent encoded this is probably an approvement. It also lets us deal with the
translation more intelligently and truncate long identifiers.

[SVN r48927]
This commit is contained in:
Daniel James 2008-09-23 19:29:01 +00:00
parent bd57856bca
commit b9f65e69a4
4 changed files with 68 additions and 47 deletions

View File

@ -20,27 +20,9 @@
<xsl:key name="named-entities" match="class|struct|union|concept|function|overloaded-function|macro|library|namespace/data-member|header/data-member|*[attribute::id]" use="@name|@id"/> <xsl:key name="named-entities" match="class|struct|union|concept|function|overloaded-function|macro|library|namespace/data-member|header/data-member|*[attribute::id]" use="@name|@id"/>
<xsl:template match="function|overloaded-function" mode="generate.id"> <xsl:template match="function|overloaded-function" mode="generate.id">
<xsl:variable name="name" select="normalize-space(@name)"/> <xsl:call-template name="fully-qualified-id">
<xsl:variable name="translated-name" <xsl:with-param name="node" select="."/>
select="translate($name, </xsl:call-template>
'~!%^&amp;*()[].,&lt;&gt;|/ +-=',
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')"/>
<xsl:choose>
<xsl:when test="count(key('named-entities', $name))=1
and ($translated-name=$name)">
<xsl:call-template name="fully-qualified-id">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="fully-qualified-id">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
<xsl:text>_</xsl:text>
<xsl:value-of select="generate-id(.)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template> </xsl:template>
<xsl:template match="classname" mode="annotation"> <xsl:template match="classname" mode="annotation">

View File

@ -28,7 +28,7 @@
<xsl:choose> <xsl:choose>
<xsl:when test="not($recursive)"> <xsl:when test="not($recursive)">
<!-- translate dots into directory separators, and replace illegal file path characters with underscores --> <!-- translate dots into directory separators, and replace illegal file path characters with underscores -->
<xsl:value-of select="translate(normalize-space(translate($basename, '.&lt;&gt;\:*?&quot;|,()!+=&amp;', '/ ' )), ' ', '_')"/> <xsl:value-of select="translate($basename, '.&lt;&gt;\:*?&quot;|,()!+=&amp;', '/_______________' )"/>
<xsl:value-of select="$html.ext"/> <xsl:value-of select="$html.ext"/>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>

View File

@ -152,7 +152,7 @@
<xsl:template match="header" mode="generate.id"> <xsl:template match="header" mode="generate.id">
<xsl:text>header.</xsl:text> <xsl:text>header.</xsl:text>
<xsl:value-of select="translate(@name, '/','.')"/> <xsl:value-of select="translate(@name, '/.', '._')"/>
</xsl:template> </xsl:template>
<xsl:template match="*" mode="passthrough"> <xsl:template match="*" mode="passthrough">

View File

@ -9,7 +9,10 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"> version="1.0">
<xsl:param name="boost.max.id.length">26</xsl:param> <!-- Maximum length of directory and file names is 31 characters.
'.html' uses 5 characters.
31 - 5 = 26 -->
<xsl:param name="boost.max.id.part.length">26</xsl:param>
<!-- Generate an ID for the entity referenced --> <!-- Generate an ID for the entity referenced -->
<xsl:template name="generate.id"> <xsl:template name="generate.id">
@ -125,42 +128,31 @@
<!-- Build the fully-qualified id of the given node --> <!-- Build the fully-qualified id of the given node -->
<xsl:template name="fully-qualified-id"> <xsl:template name="fully-qualified-id">
<xsl:param name="node"/> <xsl:param name="node"/>
<xsl:variable name="name">
<xsl:apply-templates select="$node" mode="fully-qualified-name"> <xsl:apply-templates select="$node" mode="fully-qualified-name">
<xsl:with-param name="separator" select="'@'"/> <xsl:with-param name="is.id" select="true()"/>
</xsl:apply-templates> </xsl:apply-templates>
</xsl:variable>
<xsl:value-of select="translate(normalize-space(translate($name, '.', ' ')), ' @', '_.')"/>
<xsl:if test="$node/ancestor-or-self::class-specialization|
$node/ancestor-or-self::struct-specialization|
$node/ancestor-or-self::union-specialization">
<xsl:text>_</xsl:text>
<xsl:value-of select="generate-id($node)"/>
</xsl:if>
</xsl:template> </xsl:template>
<!-- Build the fully-qualified name of the given node --> <!-- Build the fully-qualified name of the given node -->
<xsl:template name="fully-qualified-name"> <xsl:template name="fully-qualified-name">
<xsl:param name="node"/> <xsl:param name="node"/>
<xsl:param name="separator" select="'::'"/> <xsl:apply-templates select="$node" mode="fully-qualified-name"/>
<xsl:apply-templates select="$node" mode="fully-qualified-name">
<xsl:with-param name="separator" select="$separator"/>
</xsl:apply-templates>
</xsl:template> </xsl:template>
<!-- Hack to make the node we are building the current node so that the <!-- Hack to make the node we are building the current node so that the
ancestor:: syntax will work --> ancestor:: syntax will work -->
<xsl:template match="*" mode="fully-qualified-name"> <xsl:template match="*" mode="fully-qualified-name">
<xsl:param name="separator" select="'::'"/> <xsl:param name="is.id" select="false()" />
<xsl:call-template name="build-fully-qualified-name"> <xsl:call-template name="build-fully-qualified-name">
<xsl:with-param name="separator" select="$separator"/> <xsl:with-param name="is.id" select="$is.id"/>
</xsl:call-template> </xsl:call-template>
</xsl:template> </xsl:template>
<!-- The real routine that builds a fully-qualified name for the current <!-- The real routine that builds a fully-qualified name for the current
node. --> node. -->
<xsl:template name="build-fully-qualified-name"> <xsl:template name="build-fully-qualified-name">
<xsl:param name="separator" select="'::'"/> <xsl:param name="is.id" select="false()" />
<!-- The depth of qualified name element that we will print now--> <!-- The depth of qualified name element that we will print now-->
<xsl:param name="depth" select="1"/> <xsl:param name="depth" select="1"/>
@ -173,22 +165,69 @@
<xsl:choose> <xsl:choose>
<xsl:when test="$depth &gt; count($ancestors)"> <xsl:when test="$depth &gt; count($ancestors)">
<xsl:apply-templates select="." mode="print-name"/> <xsl:apply-templates select="." mode="print-id-part">
<xsl:with-param name="is.id" select="$is.id"/>
</xsl:apply-templates>
</xsl:when> </xsl:when>
<xsl:otherwise> <xsl:otherwise>
<xsl:if test="name($ancestors[$depth])='namespace' or <xsl:if test="name($ancestors[$depth])='namespace' or
count(ancestor::free-function-group)=0"> count(ancestor::free-function-group)=0">
<xsl:apply-templates select="$ancestors[$depth]" mode="print-name"/> <xsl:apply-templates select="$ancestors[$depth]" mode="print-id-part">
<xsl:value-of select="$separator"/> <xsl:with-param name="is.id" select="$is.id"/>
</xsl:apply-templates>
<xsl:choose>
<xsl:when test="$is.id"><xsl:text>.</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>::</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:if> </xsl:if>
<xsl:call-template name="build-fully-qualified-name"> <xsl:call-template name="build-fully-qualified-name">
<xsl:with-param name="separator" select="$separator"/> <xsl:with-param name="is.id" select="$is.id"/>
<xsl:with-param name="depth" select="$depth + 1"/> <xsl:with-param name="depth" select="$depth + 1"/>
</xsl:call-template> </xsl:call-template>
</xsl:otherwise> </xsl:otherwise>
</xsl:choose> </xsl:choose>
</xsl:template> </xsl:template>
<!-- Print the part of a fully qualified name for a single element -->
<xsl:template match="*" mode="print-id-part">
<xsl:param name="is.id"/>
<xsl:variable name="part">
<xsl:apply-templates select="." mode="print-name"/>
</xsl:variable>
<xsl:variable name="unique-name">
<xsl:apply-templates select="." mode="unique.name"/>
</xsl:variable>
<xsl:choose>
<xsl:when test=
"$is.id and (
string-length($part) &gt; $boost.max.id.part.length or
$unique-name = 0 or
translate($part, '.&lt;&gt;;\:*?&quot;| ', '') != $part
)">
<xsl:variable name="normalized" select="translate(normalize-space(translate($part, '.&lt;&gt;;\:*?&quot;|_', ' ')), ' ', '_')"/>
<xsl:value-of select =
"concat(
substring($normalized, 1, $boost.max.id.part.length - string-length(generate-id(.) - 1)),
concat('_', generate-id(.)))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$part"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Override this if an id might not be unique -->
<xsl:template match="*" mode="unique.name">
<xsl:value-of select="1"/>
</xsl:template>
<xsl:template match="function|overloaded-function" mode="unique.name">
<xsl:value-of select="number(count(key('named-entities', @name)) = 1)"/>
</xsl:template>
<!-- Print the name of the current node --> <!-- Print the name of the current node -->
<xsl:template match="*" mode="print-name"> <xsl:template match="*" mode="print-name">
<xsl:value-of select="@name"/> <xsl:value-of select="@name"/>