Handling toplevel docs which don't set an id



Hi,

Most GNOME docbook entries start in the format:

        <article id="index" lang="en">

However, most KDE entries start like so:

        <book lang="en">
        
yelp-db-pager already knows about both article and book as "divisions",
but it does not handle divisions which lack an "id" property well.  In
yelp-xslt-pager.c:xslt_yelp_document(), there is this code:

    page_id = xsltEvalAttrValueTemplate (ctxt, inst,
                                         (const xmlChar *) "href",
                                         NULL);
    if (page_id == NULL) {
        xsltTransformError (ctxt, NULL, inst,
                            _("No href attribute found on yelp:document"));
        /* FIXME: put a real error here */
        error = NULL;
        yelp_pager_error (pager, error);
        goto done;
    }

There are two problems with this: first, page_id will never be NULL.  If
the href is empty, it'll return "" rather than NULL.  Secondly, if it
were NULL, yelp would completely bail out here, and that doesn't "help"
anybody.  Ha Ha.

Probably the better thing to do here is to assume that documents with
empty ids are probably the toplevel "index".  I'm attaching a patch
which does this.

Please CC me on any replies, I'm not on the list yet.

Thanks,
Joe
Index: src/yelp-xslt-pager.c
===================================================================
RCS file: /cvs/gnome/yelp/src/yelp-xslt-pager.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 yelp-xslt-pager.c
--- src/yelp-xslt-pager.c       16 Nov 2005 20:51:02 -0000      1.14
+++ src/yelp-xslt-pager.c       13 Jan 2006 18:50:11 -0000
@@ -371,4 +371,14 @@ xslt_yelp_document (xsltTransformContext
        yelp_pager_error (pager, error);
        goto done;
     }
+
+    /*
+     * Most KDE docs don't have an id at the toplevel.  If we see a blank
+     * id, assume it's the toplevel index.
+     */
+    if (xmlStrcmp (page_id, BAD_CAST "") == 0) {
+       xmlFree (page_id);
+       page_id = xmlStrdup (BAD_CAST "index");
+    }
+
     d (g_print ("  page_id = \"%s\"\n", page_id));

     old_outfile = ctxt->outputFile;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]