Strip `xsl' namespace prefix from path.xsl

This also sets the XSLT version to 2.0.

* src/current/include/preproc/path.xsl: Strip `xsl' namespace prefix.
master
Mike Gerwitz 2017-07-12 10:10:45 -04:00
parent c156c10989
commit 7d9fb48e11
1 changed files with 146 additions and 147 deletions

View File

@ -2,7 +2,7 @@
<!-- <!--
Operations on paths Operations on paths
Copyright (C) 2016 LoVullo Associates, Inc. Copyright (C) 2017 LoVullo Associates, Inc.
This file is part of TAME. This file is part of TAME.
@ -20,229 +20,228 @@
along with this program. If not, see along with this program. If not, see
<http://www.gnu.org/licenses/>. <http://www.gnu.org/licenses/>.
--> -->
<xsl:stylesheet version="1.0" <stylesheet version="2.0"
xmlns="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:preproc="http://www.lovullo.com/rater/preproc"> xmlns:preproc="http://www.lovullo.com/rater/preproc">
<xsl:template name="preproc:get-path"> <template name="preproc:get-path">
<xsl:param name="path" /> <param name="path" />
<xsl:param name="prev" select="''" /> <param name="prev" select="''" />
<xsl:variable name="first" select="substring-before( $path, '/' )" /> <variable name="first" select="substring-before( $path, '/' )" />
<xsl:variable name="rest" select="substring-after( $path, '/' )" /> <variable name="rest" select="substring-after( $path, '/' )" />
<xsl:choose> <choose>
<!-- if there's no $first, then there is no path separator, in which case <!-- if there's no $first, then there is no path separator, in which case
we're done; if there's no rest, then there is a path separator, but it we're done; if there's no rest, then there is a path separator, but it
resulted in an empty string, meanaing that it ends in a path resulted in an empty string, meanaing that it ends in a path
separator, in which case we are also done --> separator, in which case we are also done -->
<xsl:when test="not( $first ) or not( $rest )"> <when test="not( $first ) or not( $rest )">
<!-- no more path separators; we're done --> <!-- no more path separators; we're done -->
<xsl:value-of select="$prev" /> <value-of select="$prev" />
</xsl:when> </when>
<!-- keep recursing --> <!-- keep recursing -->
<xsl:otherwise> <otherwise>
<xsl:call-template name="preproc:get-path"> <call-template name="preproc:get-path">
<xsl:with-param name="path" select="$rest" /> <with-param name="path" select="$rest" />
<xsl:with-param name="prev"> <with-param name="prev">
<xsl:if test="not( $prev = '' )"> <if test="not( $prev = '' )">
<xsl:value-of select="concat( $prev, '/' )" /> <value-of select="concat( $prev, '/' )" />
</xsl:if> </if>
<xsl:value-of select="$first" /> <value-of select="$first" />
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:template> </template>
<!-- FIXME: duplicate code with above --> <!-- FIXME: duplicate code with above -->
<xsl:template name="preproc:get-basename"> <template name="preproc:get-basename">
<xsl:param name="path" /> <param name="path" />
<xsl:param name="prev" select="''" /> <param name="prev" select="''" />
<xsl:variable name="first" select="substring-before( $path, '/' )" /> <variable name="first" select="substring-before( $path, '/' )" />
<xsl:variable name="rest" select="substring-after( $path, '/' )" /> <variable name="rest" select="substring-after( $path, '/' )" />
<xsl:choose> <choose>
<!-- if there's no $first, then there is no path separator, in which case <!-- if there's no $first, then there is no path separator, in which case
we're done; if there's no rest, then there is a path separator, but it we're done; if there's no rest, then there is a path separator, but it
resulted in an empty string, meanaing that it ends in a path resulted in an empty string, meanaing that it ends in a path
separator, in which case we are also done --> separator, in which case we are also done -->
<xsl:when test="not( $first ) or not( $rest )"> <when test="not( $first ) or not( $rest )">
<!-- no more path separators; we're done --> <!-- no more path separators; we're done -->
<xsl:value-of select="$path" /> <value-of select="$path" />
</xsl:when> </when>
<!-- keep recursing --> <!-- keep recursing -->
<xsl:otherwise> <otherwise>
<xsl:call-template name="preproc:get-basename"> <call-template name="preproc:get-basename">
<xsl:with-param name="path" select="$rest" /> <with-param name="path" select="$rest" />
<xsl:with-param name="prev"> <with-param name="prev">
<xsl:if test="not( $prev = '' )"> <if test="not( $prev = '' )">
<xsl:value-of select="concat( $prev, '/' )" /> <value-of select="concat( $prev, '/' )" />
</xsl:if> </if>
<xsl:value-of select="$first" /> <value-of select="$first" />
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:template> </template>
<xsl:template name="preproc:resolv-path"> <template name="preproc:resolv-path">
<xsl:param name="path" /> <param name="path" />
<!-- in order: strip //, process ../, strip ./ --> <!-- in order: strip //, process ../, strip ./ -->
<xsl:call-template name="preproc:strip-sdot-path"> <call-template name="preproc:strip-sdot-path">
<xsl:with-param name="path"> <with-param name="path">
<xsl:call-template name="preproc:resolv-rel-path"> <call-template name="preproc:resolv-rel-path">
<xsl:with-param name="path"> <with-param name="path">
<xsl:call-template name="preproc:strip-extra-path"> <call-template name="preproc:strip-extra-path">
<xsl:with-param name="path" select="$path" /> <with-param name="path" select="$path" />
</xsl:call-template> </call-template>
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:template> </template>
<!-- XXX: warning, this won't like 'foo../' --> <!-- XXX: warning, this won't like 'foo../' -->
<xsl:template name="preproc:resolv-rel-path"> <template name="preproc:resolv-rel-path">
<xsl:param name="path" /> <param name="path" />
<!-- relative paths --> <!-- relative paths -->
<xsl:variable name="before" select="substring-before( $path, '../' )" /> <variable name="before" select="substring-before( $path, '../' )" />
<xsl:variable name="after" select="substring-after( $path, '../' )" /> <variable name="after" select="substring-after( $path, '../' )" />
<xsl:choose> <choose>
<xsl:when test="$before"> <when test="$before">
<xsl:call-template name="preproc:resolv-rel-path"> <call-template name="preproc:resolv-rel-path">
<xsl:with-param name="path"> <with-param name="path">
<!-- remove the last directory before the ../ --> <!-- remove the last directory before the ../ -->
<xsl:variable name="before-path"> <variable name="before-path">
<xsl:call-template name="preproc:get-path"> <call-template name="preproc:get-path">
<xsl:with-param name="path" select="$before" /> <with-param name="path" select="$before" />
</xsl:call-template> </call-template>
</xsl:variable> </variable>
<xsl:value-of select="$before-path" /> <value-of select="$before-path" />
<!-- the above get-path call will strip the trailing slash --> <!-- the above get-path call will strip the trailing slash -->
<xsl:if test="not( $before-path = '' ) and not( $after = '' )"> <if test="not( $before-path = '' ) and not( $after = '' )">
<xsl:text>/</xsl:text> <text>/</text>
</xsl:if> </if>
<xsl:value-of select="$after" /> <value-of select="$after" />
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:when> </when>
<!-- if there's no $before but there is an $after, then we must begin with <!-- if there's no $before but there is an $after, then we must begin with
'../', which we can do nothing with; output it and continue processing '../', which we can do nothing with; output it and continue processing
the remainder of the path --> the remainder of the path -->
<xsl:when test="$after"> <when test="$after">
<xsl:text>../</xsl:text> <text>../</text>
<xsl:call-template name="preproc:resolv-rel-path"> <call-template name="preproc:resolv-rel-path">
<xsl:with-param name="path" select="$after" /> <with-param name="path" select="$after" />
</xsl:call-template> </call-template>
</xsl:when> </when>
<!-- no relative paths remaining --> <!-- no relative paths remaining -->
<xsl:otherwise> <otherwise>
<xsl:value-of select="$path" /> <value-of select="$path" />
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:template> </template>
<xsl:template name="preproc:strip-sdot-path"> <template name="preproc:strip-sdot-path">
<xsl:param name="path" /> <param name="path" />
<xsl:choose> <choose>
<!-- the only time this should be called with an unresolved relative path <!-- the only time this should be called with an unresolved relative path
is if it begins with one, in which case we'll simply output it and is if it begins with one, in which case we'll simply output it and
continue processing without it --> continue processing without it -->
<xsl:when test="starts-with( $path, '../' )"> <when test="starts-with( $path, '../' )">
<xsl:text>../</xsl:text> <text>../</text>
<!-- continue processing without it --> <!-- continue processing without it -->
<xsl:call-template name="preproc:strip-sdot-path"> <call-template name="preproc:strip-sdot-path">
<xsl:with-param name="path" select="substring-after( $path, '../' )" /> <with-param name="path" select="substring-after( $path, '../' )" />
</xsl:call-template> </call-template>
</xsl:when> </when>
<!-- path is safe for processing --> <!-- path is safe for processing -->
<xsl:otherwise> <otherwise>
<xsl:variable name="a" select="substring-before( $path, './' )" /> <variable name="a" select="substring-before( $path, './' )" />
<xsl:variable name="b" select="substring-after( $path, './' )" /> <variable name="b" select="substring-after( $path, './' )" />
<xsl:choose> <choose>
<!-- if we found one, recurse --> <!-- if we found one, recurse -->
<xsl:when test="$a or $b"> <when test="$a or $b">
<xsl:call-template name="preproc:strip-sdot-path"> <call-template name="preproc:strip-sdot-path">
<xsl:with-param name="path"> <with-param name="path">
<xsl:value-of select="$a" /> <value-of select="$a" />
<xsl:if test="$a and $b"> <if test="$a and $b">
<xsl:text>/</xsl:text> <text>/</text>
</xsl:if> </if>
<xsl:value-of select="$b" /> <value-of select="$b" />
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:when> </when>
<!-- done --> <!-- done -->
<xsl:otherwise> <otherwise>
<xsl:value-of select="$path" /> <value-of select="$path" />
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:template> </template>
<xsl:template name="preproc:strip-extra-path"> <template name="preproc:strip-extra-path">
<xsl:param name="path" /> <param name="path" />
<xsl:variable name="a" select="substring-before( $path, '//' )" /> <variable name="a" select="substring-before( $path, '//' )" />
<xsl:variable name="b" select="substring-after( $path, '//' )" /> <variable name="b" select="substring-after( $path, '//' )" />
<xsl:choose> <choose>
<!-- if we found one, recurse --> <!-- if we found one, recurse -->
<xsl:when test="$a or $b"> <when test="$a or $b">
<xsl:call-template name="preproc:strip-extra-path"> <call-template name="preproc:strip-extra-path">
<xsl:with-param name="path"> <with-param name="path">
<xsl:value-of select="$a" /> <value-of select="$a" />
<xsl:if test="$a and $b"> <if test="$a and $b">
<xsl:text>/</xsl:text> <text>/</text>
</xsl:if> </if>
<xsl:value-of select="$b" /> <value-of select="$b" />
</xsl:with-param> </with-param>
</xsl:call-template> </call-template>
</xsl:when> </when>
<!-- we're done! --> <!-- we're done! -->
<xsl:otherwise> <otherwise>
<xsl:value-of select="$path" /> <value-of select="$path" />
</xsl:otherwise> </otherwise>
</xsl:choose> </choose>
</xsl:template> </template>
</xsl:stylesheet> </stylesheet>