aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/libxslt-generated-ids.patch
blob: 1cd2363d6aaeea37e8725796eca2fac4851a195d (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
This makes generated IDs deterministic.

Written by Daniel Veillard.

This should be fixed in next release (2.29).
See https://bugzilla.gnome.org/show_bug.cgi?id=751621.

diff --git a/libxslt/functions.c b/libxslt/functions.c
index 6448bde..5b00a6d 100644
--- a/libxslt/functions.c
+++ b/libxslt/functions.c
@@ -651,6 +651,63 @@ xsltFormatNumberFunction(xmlXPathParserContextPtr ctxt, int nargs)
 }
 
 /**
+ * xsltCleanupIds:
+ * @ctxt: the transformation context
+ * @root: the root of the resulting document
+ *
+ * This clean up ids which may have been saved in Element contents
+ * by xsltGenerateIdFunction() to provide stable IDs on elements.
+ *
+ * Returns the number of items cleaned or -1 in case of error
+ */
+int
+xsltCleanupIds(xsltTransformContextPtr ctxt, xmlNodePtr root) {
+    xmlNodePtr cur;
+    int count = 0;
+
+    if ((ctxt == NULL) || (root == NULL))
+        return(-1);
+    if (root->type != XML_ELEMENT_NODE)
+        return(-1);
+
+    cur = root;
+    while (cur != NULL) {
+	if (cur->type == XML_ELEMENT_NODE) {
+	    if (cur->content != NULL) {
+	        cur->content = NULL;
+		count++;
+	    }
+	    if (cur->children != NULL) {
+		cur = cur->children;
+		continue;
+	    }
+	}
+	if (cur->next != NULL) {
+	    cur = cur->next;
+	    continue;
+	}
+	do {
+	    cur = cur->parent;
+	    if (cur == NULL)
+		break;
+	    if (cur == (xmlNodePtr) root) {
+		cur = NULL;
+		break;
+	    }
+	    if (cur->next != NULL) {
+		cur = cur->next;
+		break;
+	    }
+	} while (cur != NULL);
+    }
+
+fprintf(stderr, "Attributed %d IDs for element, cleaned up %d\n",
+        ctxt->nextid, count);
+
+    return(count);
+}
+
+/**
  * xsltGenerateIdFunction:
  * @ctxt:  the XPath Parser context
  * @nargs:  the number of arguments
@@ -701,7 +758,39 @@ xsltGenerateIdFunction(xmlXPathParserContextPtr ctxt, int nargs){
     if (obj)
         xmlXPathFreeObject(obj);
 
-    val = (long)((char *)cur - (char *)&base_address);
+    /*
+     * Try to provide stable ID for generated document:
+     *   - usually ID are computed to be placed on elements via attributes
+     *     so using the element as the node for the ID
+     *   - the cur->content should be a correct placeholder for this, we use
+     *     it to hold element node numbers in xmlXPathOrderDocElems to
+     *     speed up XPath too
+     *   - xsltCleanupIds() clean them up before handing the XSLT output
+     *     to the API client.
+     *   - other nodes types use the node address method but that should
+     *     not end up in resulting document ID
+     *   - we can enable this by default without risk of performance issues
+     *     only the one pass xsltCleanupIds() is added
+     */
+    if (cur->type == XML_ELEMENT_NODE) {
+        if (cur->content == NULL) {
+	    xsltTransformContextPtr tctxt;
+
+	    tctxt = xsltXPathGetTransformContext(ctxt);
+	    if (tctxt == NULL) {
+		val = (long)((char *)cur - (char *)&base_address);
+	    } else {
+		tctxt->nextid++;
+		val = tctxt->nextid;
+		cur->content = (void *) (val);
+	    }
+	} else {
+	    val = (long) cur->content;
+	}
+    } else {
+	val = (long)((char *)cur - (char *)&base_address);
+    }
+
     if (val >= 0) {
       sprintf((char *)str, "idp%ld", val);
     } else {
diff --git a/libxslt/functions.h b/libxslt/functions.h
index e0e0bf9..4a1e163 100644
--- a/libxslt/functions.h
+++ b/libxslt/functions.h
@@ -64,6 +64,13 @@ XSLTPUBFUN void XSLTCALL
 					 int nargs);
 
 /*
+ * Cleanup for ID generation
+ */
+XSLTPUBFUN int XSLTCALL
+	xsltCleanupIds			(xsltTransformContextPtr ctxt,
+					 xmlNodePtr root);
+
+/*
  * And the registration
  */
 
diff --git a/libxslt/transform.c b/libxslt/transform.c
index 24f9eb2..2bdf6bf 100644
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -700,6 +700,7 @@ xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) {
     cur->traceCode = (unsigned long*) &xsltDefaultTrace;
     cur->xinclude = xsltGetXIncludeDefault();
     cur->keyInitLevel = 0;
+    cur->nextid = 0;
 
     return(cur);
 
@@ -6092,6 +6093,13 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
     if (root != NULL) {
         const xmlChar *doctype = NULL;
 
+        /*
+	 * cleanup ids which may have been saved in Elements content ptrs
+	 */
+	if (ctxt->nextid != 0) {
+	    xsltCleanupIds(ctxt, root);
+	}
+
         if ((root->ns != NULL) && (root->ns->prefix != NULL))
 	    doctype = xmlDictQLookup(ctxt->dict, root->ns->prefix, root->name);
 	if (doctype == NULL)
diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h
index 95e8fe6..8eedae4 100644
--- a/libxslt/xsltInternals.h
+++ b/libxslt/xsltInternals.h
@@ -1782,6 +1782,8 @@ struct _xsltTransformContext {
     int maxTemplateVars;
     unsigned long opLimit;
     unsigned long opCount;
+
+    unsigned long nextid;/* for generating stable ids */
 };
 
 /**
ackage-management.scm (xstow, modules)[home-page]: Likewise. * gnu/packages/parallel.scm (xjobs)[home-page]: Likewise. * gnu/packages/pdf.scm (podofo, qpdf, xournal, impressive)[home-page]: Likewise. * gnu/packages/perl.scm (perl-math-vecstat, perltidy)[home-page]: Likewise. * gnu/packages/photo.scm (libpano13, enblend-enfuse, hugin)[home-page]: Likewise. * gnu/packages/plan9.scm (drawterm)[home-page]: Likewise. * gnu/packages/plotutils.scm (guile-charting, ploticus)[home-page]: Likewise. * gnu/packages/popt.scm (argtable, popt)[home-page]: Likewise. * gnu/packages/profiling.scm (otf2)[home-page]: Likewise. * gnu/packages/pulseaudio.scm (pulseaudio)[home-page]: Likewise. * gnu/packages/python-check.scm (python-mypy)[home-page]: Likewise. * gnu/packages/python-web.scm (python-cssutils) (python-translationstring)[home-page]: Likewise. * gnu/packages/python-xyz.scm (python-diskcache, python-doxyqml) (python-docutils, python-pexpect, python-importlib-resources) (python-simplegeneric, python-urwid, python-xlrd, python-xlwt) (python-pyasn1, python-pythondialog, python-tftpy, python-random2) (python-arcp, python-pyopengl, python-sortedcollections) (python-sortedcontainers, python-yapsy, python-pydispatcher) (python-posix-ipc)[home-page]: Likewise. * gnu/packages/qt.scm (qwt, libqglviewer, signond)[home-page]: Likewise. * gnu/packages/radio.scm (unixcw, gnuais)[home-page]: Likewise. * gnu/packages/raspberry-pi.scm (bcm2835)[home-page]: Likewise. * gnu/packages/rdf.scm (clucene, rasqal, redland)[home-page]: Likewise. * gnu/packages/regex.scm (tre)[home-page]: Likewise. * gnu/packages/rsync.scm (librsync)[home-page]: Likewise. * gnu/packages/ruby.scm (ruby-packnga, ruby-nokogiri, ruby-oj, ruby-ox) (ruby-sinatra, ruby-citrus, ruby-cbor, ruby-roda)[home-page]: Likewise. * gnu/packages/scheme.scm (scheme48, tinyscheme)[home-page]: Likewise. * gnu/packages/screen.scm (dtach)[home-page]: Likewise. * gnu/packages/scsi.scm (sg3-utils)[home-page]: Likewise. * gnu/packages/sdl.scm (libmikmod, sdl-pango)[home-page]: Likewise. * gnu/packages/shellutils.scm (hstr, rig)[home-page]: Likewise. * gnu/packages/simulation.scm (python-dolfin-adjoint)[home-page]: Likewise. * gnu/packages/smalltalk.scm (smalltalk)[home-page]: Likewise. * gnu/packages/speech.scm (espeak)[home-page]: Likewise. * gnu/packages/stalonetray.scm (stalonetray)[home-page]: Likewise. * gnu/packages/statistics.scm (jags, r-mass, r-class, r-lattice) (r-matrix, r-nnet, r-spatial, r-bit, r-bit64, r-digest, r-xtable) (python-statsmodels, r-ade4, r-latticeextra, r-rcurl, r-xml, r-mvtnorm) (r-robustbase, r-minqa, r-fdrtool, java-jdistlib, xlispstat)[home-page]: Likewise. * gnu/packages/swig.scm (swig)[home-page]: Likewise. * gnu/packages/task-management.scm (wtime)[home-page]: Likewise. * gnu/packages/tcl.scm (itcl, tclxml, tclx)[home-page]: Likewise. * gnu/packages/terminals.scm (libtermkey, mlterm, libvterm) (libvterm)[home-page]: Likewise. * gnu/packages/tex.scm (texlive-lm, texlive-lm-math, texlive-cs) (texlive-csplain, biber, texmaker)[home-page]: Likewise. * gnu/packages/text-editors.scm (joe)[home-page]: Likewise. * gnu/packages/textutils.scm (drm-tools, docx2txt)[home-page]: Likewise. * gnu/packages/tv.scm (tvtime)[home-page]: Likewise. * gnu/packages/unicode.scm (libunibreak)[home-page]: Likewise. * gnu/packages/upnp.scm (libupnp)[home-page]: Likewise. * gnu/packages/version-control.scm (cvs)[home-page]: Likewise. * gnu/packages/video.scm (transcode, libquicktime, mjpegtools, aalib) (liba52, libmpeg2, x265, libdv, dvdauthor, aegisub, pitivi, gavl) (dvdbackup, guvcview, video-contact-sheet)[home-page]: Likewise. * gnu/packages/virtualization.scm (bochs)[home-page]: Likewise. * gnu/packages/w3m.scm (w3m)[home-page]: Likewise. * gnu/packages/web.scm (qjson, libquvi-scripts, libquvi, quvi) (tidy-html, htmlcxx)[home-page]: Likewise. * gnu/packages/wm.scm (evilwm, menumaker)[home-page]: Likewise. * gnu/packages/wv.scm (wv)[home-page]: Likewise. * gnu/packages/wxwidgets.scm (wxsvg)[home-page]: Likewise. * gnu/packages/xdisorg.scm (mtdev, xsel)[home-page]: Likewise. * gnu/packages/xfig.scm (xfig, transfig)[home-page]: Likewise. * gnu/packages/xml.scm (openjade, python-pyxb, xmlstarlet, xmlrpc-c) (opensp)[home-page]: Likewise. * gnu/packages/xorg.scm (xf86-video-qxl)[home-page]: Likewise. Tobias Geerinckx-Rice 2022-08-11Merge branch 'staging' into core-updatesMarius Bakke 2022-07-31gnu: qttools: Rename to qttools-5....Automated with: git grep -l qttools | xargs sed 's/\bqttools\b/\0-5/g' -i git checkout NEWS Maxim Cournoyer 2022-06-08Merge branch 'master' into core-updatesLudovic Courtès 2022-05-31gnu: pdf2djvu: Disable tests to avoid Python 2 dependencies....* gnu/packages/djvu.scm (pdf2djvu)[tests]: Set to #f. [test-target]: Delete argument. [native-inputs]: Use new style. Delete python-2 and python2-nose. [inputs]: Use new style. Maxim Cournoyer 2022-05-31gnu: didjvu: Switch to a Python 3 compatible fork....* gnu/packages/djvu.scm (didjvu)[source]: Switch to a Python 3 compatible fork. [native-inputs, inputs]: Move below arguments field. Use new style. Replace the Python 2 inputs by their Python 3 equivalents. Maxim Cournoyer 2022-05-31gnu: Remove djvusmooth....* gnu/packages/djvu.scm (djvusmooth): Delete variable. Maxim Cournoyer 2022-05-31gnu: ocrodjvu: Use a Python 3 compatible fork....* gnu/packages/djvu.scm (ocrodjvu)[source]: Update URL to Python 3 fork. [inputs]: Use new style. Remove python2-subprocess32. Replace all other Python 2 inputs by their Python 3 equivalent. Add python-future and python-regex. [arguments]: Use gexps, and adjust accordingly, using this-package-input and search-input-file. Maxim Cournoyer