Skip to content

Instantly share code, notes, and snippets.

@jkonrath
Last active August 4, 2020 23:06
Show Gist options
  • Save jkonrath/b9c082fa74c6991242477f5a4c6ad0b4 to your computer and use it in GitHub Desktop.
Save jkonrath/b9c082fa74c6991242477f5a4c6ad0b4 to your computer and use it in GitHub Desktop.
XSLT - fix broken Doxygen return list
<!-- XSL 1.0. (This isn't a complete file, just an example.)
Doxygen likes to make broken lists that look like this:
<simplesect kind="return"><para>ABC_SUCCESS on success <linebreak/>
ABC_ERROR_INVALID_PARAMETER if the input parameter is NULL <linebreak/>
ABC_ERROR_DEVICE_NOT_FOUND if the device is not present or supported <linebreak/>
ABC_ERROR_CANNOT_ACTIVATE_SERVER if the sensor server cannot be started </para></simplesect>
That's not a list of elements. It's a single element that's polluted with linebreaks.
-->
<!-- First, use this to massage all of your <para> elements accordingly... -->
<xsl:template match="para">
<xsl:choose>
<!-- a bunch of other when/tests here ... -->
<xsl:when test="linebreak">
<xsl:for-each select="node()">
<xsl:call-template name="splitup">
<xsl:with-param name="list"><xsl:value-of select="."/></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:when>
</xsl:template>
<!--
Make it look like this:
<returnval>this is one</returnval>
<returnval>this is two</returnval>
<returnval>this is three</returnval>
The substring chop is because all but the first return begin with a space.
-->
<xsl:template name="splitup">
<xsl:param name="list" />
<xsl:choose>
<xsl:when test="$list=''">
</xsl:when>
<xsl:when test="substring($list,2,1) = ' '">
<returnval><xsl:value-of select="substring($list,3)"/></returnval>
</xsl:when>
<xsl:otherwise>
<returnval><xsl:value-of select="$list"/></returnval>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment