1

I have the following XML in a directory with the required entity file in place:

<!DOCTYPE refentry [ <!ENTITY % mathent SYSTEM "math.ent"> %mathent; ]>

<!-- Converted by db4-upgrade version 1.1 -->

<refentry xmlns="http://docbook.org/ns/docbook" version="5.0" xml:id="glBlendEquation">
    <info>
        <copyright>
            <year>1991-2006</year>
            <holder>Silicon Graphics, Inc.</holder>
        </copyright>
        <copyright>
            <year>2010-2014</year>
            <holder>Khronos Group</holder>
        </copyright>
    </info>
    <refmeta>
        <refentrytitle>glBlendEquation</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>glBlendEquation</refname>
        <refpurpose>specify the equation used for both the RGB blend equation and the Alpha blend equation</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>glBlendEquation</function></funcdef>
                <paramdef>GLenum <parameter>mode</parameter></paramdef>
            </funcprototype>
            <funcprototype>
                <funcdef>void <function>glBlendEquationi</function></funcdef>
                <paramdef>GLuint <parameter>buf</parameter></paramdef>
                <paramdef>GLenum <parameter>mode</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
</refentry>

I am applying the following XSL:

<?xml version="1.0"?>

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:fns="http://www.w3.org/2002/Math/preference"
  xmlns:mml="http://www.w3.org/1998/Math/MathML"
  extension-element-prefixes="msxsl fns doc"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:doc="http://www.dcarlisle.demon.co.uk/xsldoc"
  xmlns:ie5="http://www.w3.org/TR/WD-xsl"
  exclude-result-prefixes="h ie5 fns msxsl fns doc mml"
>

<xsl:template match="refpurpose">
    <xsl:value-of select="." />
</xsl:template>

<xsl:template match="/">
{
<xsl:apply-templates select="refnamediv/refpurpose" />
}
</xsl:template>

</xsl:stylesheet>

I expect the output to be:

<?xml version="1.0"?>

{
specify the equation used for both the RGB blend equation and the Alpha blend equation
}

But the output I'm getting is:

<?xml version="1.0"?>

{

}

Why is my "refpurpose" template not matching? I'm using xsltproc.

NeomerArcana
  • 1,978
  • 3
  • 23
  • 50
  • Welcome to the club: a search for "XSLT default namespace" finds 728 other people who have fallen into the same bewildering trap. Closing this as a duplicate is no criticism; you would only know it was a duplicate question if you already knew the answer. – Michael Kay May 10 '20 at 08:01

1 Answers1

0

You have to take into account the default namespace.

Add

xmlns:db="http://docbook.org/ns/docbook"

to xsl:stylesheet and use the defined namespace prefix ahead of all elements in the default namespace: db:refpurpose, db:refnamediv, etc.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • 1
    An in addition, `refnamediv` is not a child of the root node. – michael.hor257k May 10 '20 at 04:11
  • @michael.hor257k `refnamediv` isn't a child of the root? Isn't `refentry` the root node? – NeomerArcana May 10 '20 at 06:48
  • 1
    No. `refentry` is the *root element*. You are in the context of the `/` *root node* (a.k.a. the *document node*). From this context, the path to `refpurpose` is `refentry/refnamediv/refpurpose` (with the appropriate prefixes). – michael.hor257k May 10 '20 at 07:13
  • Thanks to @michael.hor257k for explaining as important an issue as the one regarding the default namespace. – kjhughes May 10 '20 at 13:36