[libvirt PATCH] docs: Fix template matching in page.xsl

Martin Kletzander posted 1 patch 2 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/805bc8c85a8446a741c63659b1fa52e9286efab3.1645432962.git.mkletzan@redhat.com
Test syntax-check failed
docs/page.xsl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[libvirt PATCH] docs: Fix template matching in page.xsl
Posted by Martin Kletzander 2 years, 2 months ago
Our last default template had a match of "node()" which incidentally matched
everything, including text nodes.  Since this has the same priority according to
the XSLT spec, section 5.5:

  https://www.w3.org/TR/1999/REC-xslt-19991116#conflict

this is an error.  Also according to the same spec section, the XSLT processor
may signal the error or pick the last rule.

This was uncovered with libxslt 1.1.35 which contains the following commit:

  https://gitlab.gnome.org/GNOME/libxslt/-/commit/b0074eeca3c6b21b4da14fdf712b853900c51635

which makes the build fail with:

  runtime error: file ../docs/page.xsl line 223 element element
  xsl:element: The effective name '' is not a valid QName.

because our last rule also matches text nodes and we are trying to extract the
node name out of them.

To fix this we change the match to "*" which only matches elements and not all
the nodes, and to avoid any possible errors with different XSLT processors we
also bump the priority of the match="text()" rule a little higher, just in case
someone needs to use an XSLT processor that chooses signalling the error instead
of the optional recovery.

https://bugs.gentoo.org/833586

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 docs/page.xsl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/page.xsl b/docs/page.xsl
index fd67918d3b08..72a6fa084235 100644
--- a/docs/page.xsl
+++ b/docs/page.xsl
@@ -215,11 +215,11 @@
     </xsl:element>
   </xsl:template>
 
-  <xsl:template match="text()" mode="copy">
+  <xsl:template match="text()" mode="copy" priority="0">
     <xsl:value-of select="."/>
   </xsl:template>
 
-  <xsl:template match="node()" mode="copy">
+  <xsl:template match="*" mode="copy">
     <xsl:element name="{name()}">
       <xsl:copy-of select="./@*"/>
       <xsl:apply-templates mode="copy" />
-- 
2.35.1

Re: [libvirt PATCH] docs: Fix template matching in page.xsl
Posted by Michal Prívozník 2 years, 2 months ago
On 2/21/22 09:42, Martin Kletzander wrote:
> Our last default template had a match of "node()" which incidentally matched
> everything, including text nodes.  Since this has the same priority according to
> the XSLT spec, section 5.5:
> 
>   https://www.w3.org/TR/1999/REC-xslt-19991116#conflict
> 
> this is an error.  Also according to the same spec section, the XSLT processor
> may signal the error or pick the last rule.
> 
> This was uncovered with libxslt 1.1.35 which contains the following commit:
> 
>   https://gitlab.gnome.org/GNOME/libxslt/-/commit/b0074eeca3c6b21b4da14fdf712b853900c51635
> 
> which makes the build fail with:
> 
>   runtime error: file ../docs/page.xsl line 223 element element
>   xsl:element: The effective name '' is not a valid QName.
> 
> because our last rule also matches text nodes and we are trying to extract the
> node name out of them.
> 
> To fix this we change the match to "*" which only matches elements and not all
> the nodes, and to avoid any possible errors with different XSLT processors we
> also bump the priority of the match="text()" rule a little higher, just in case
> someone needs to use an XSLT processor that chooses signalling the error instead
> of the optional recovery.
> 
> https://bugs.gentoo.org/833586
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  docs/page.xsl | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)


Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal