diff options
author | Ulrich Müller <ulm@gentoo.org> | 2023-10-30 18:45:02 +0100 |
---|---|---|
committer | Ulrich Müller <ulm@gentoo.org> | 2023-11-02 18:03:11 +0100 |
commit | bc2e4a7c7f83310ff46f1cf489fea0249ef63137 (patch) | |
tree | 4a5ff25534ab289f41681dd6659f63a22f0c28a4 | |
parent | *.xsl: XML declaration, local variables for Emacs, whitespace fixes (diff) | |
download | devmanual-bc2e4a7c7f83310ff46f1cf489fea0249ef63137.tar.gz devmanual-bc2e4a7c7f83310ff46f1cf489fea0249ef63137.tar.bz2 devmanual-bc2e4a7c7f83310ff46f1cf489fea0249ef63137.zip |
depend.xsl: Canonicalise output paths
Convert to absolute paths in XSLT, so postprocessing with sed is
no longer needed.
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | depend.xsl | 23 |
2 files changed, 16 insertions, 9 deletions
@@ -74,7 +74,7 @@ appendices/todo-list/index.html: $(XMLS) # Generate the list of dependencies with XSLT, which appears to be a # better tool for this than make. .depend: $(XMLS) eclass-reference/text.xml depend.xsl devbook.xsl - @xsltproc depend.xsl $(XMLS) | sed ':x;s%[^ /]*/\.\./%%;tx' > $@ + @xsltproc depend.xsl $(XMLS) > $@ install: all set -e; \ @@ -1,8 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns:str="http://exslt.org/strings" xmlns:exslt="http://exslt.org/common" - extension-element-prefixes="exslt xsl" - exclude-result-prefixes="exslt xsl"> + extension-element-prefixes="str exslt xsl" + exclude-result-prefixes="str exslt xsl"> <xsl:import href="devbook.xsl"/> <xsl:output method="text"/> @@ -20,12 +21,18 @@ <xsl:variable name="self" select="/guide/@self"/> <xsl:value-of select="concat($self, 'index.html:')"/> <xsl:for-each select="exslt:node-set($refs)//a/@href[. != '#']"> - <!-- At this point, the path can contain ".." components and - should be canonicalised, but string processing in XPath 1.0 - sucks (no pattern matching!). It is easier to pipe the output - through sed instead. --> - <xsl:value-of select="concat(' ', $self, - substring-before(., 'index.html'), 'text.xml')"/> + <xsl:text> </xsl:text> + <xsl:variable name="path" select="substring-before(., 'index.html')"/> + <!-- At this point, $path can start with zero or more ".." components + and is relative to $self. Convert it to an absolute path. --> + <xsl:variable name="up" select="count(str:tokenize($path, '/')[. = '..'])"/> + <xsl:for-each select="str:tokenize($self, '/')[position() <= last() - $up]"> + <xsl:value-of select="concat(., '/')"/> + </xsl:for-each> + <xsl:for-each select="str:tokenize($path, '/')[position() > $up]"> + <xsl:value-of select="concat(., '/')"/> + </xsl:for-each> + <xsl:text>text.xml</xsl:text> </xsl:for-each> <xsl:value-of select="$newline"/> </xsl:template> |