Subject: | media_type and output_encoding and imported stylesheets |
If the media type or output encoding of an XSLT stylesheet are defined
in the xsl:output element of a file imported with xsl:import, the
methods media_type and output_encoding return the wrong result. The
solution is to use the macro XSLT_GET_IMPORT_PTR to retrieve the values.
I also don't understand why the media_type method tries to find the
xsl:output tag manually if the media type isn't set. I think this isn't
necessary except if you need the media type before running the
transformation. And the manual detection also doesn't work with imported
stylesheets.
I attached a patch against XML-LibXSLT-1.61 that fixes the problem and
removes the manual media type detection.
Subject: | XML-LibXSLT-1.61-nik1.patch |
diff -urN XML-LibXSLT-1.61/LibXSLT.xs XML-LibXSLT-1.61-nik1/LibXSLT.xs
--- XML-LibXSLT-1.61/LibXSLT.xs 2006-09-18 22:43:57.000000000 +0200
+++ XML-LibXSLT-1.61-nik1/LibXSLT.xs 2006-11-17 16:08:52.000000000 +0100
@@ -1017,47 +1017,40 @@
char *
media_type(self)
xsltStylesheetPtr self
+ PREINIT:
+ xmlChar *mediaType;
+ xmlChar *method;
CODE:
- RETVAL = (char *)self->mediaType;
- if (RETVAL == NULL) {
- /* OK, that was borked. Try finding xsl:output tag manually... */
- xmlNodePtr root = xmlDocGetRootElement(self->doc);
- xmlNodePtr cld = root->children;
- while ( cld != NULL ) {
- if ( xmlStrcmp( (const xmlChar *) "output", cld->name ) == 0
- && cld->ns != NULL
- && xmlStrcmp((const xmlChar*) "http://www.w3.org/1999/XSL/Transform", cld->ns->href ) == 0 )
- {
- break;
- }
- cld = cld->next;
- }
-
- if (cld != NULL) {
- RETVAL = (char *) xmlGetProp(cld, (const xmlChar*)"media-type");
- }
-
- if (RETVAL == NULL) {
- RETVAL = "text/xml";
- /* this below is rather simplistic, but should work for most cases */
- if (self->method != NULL) {
- if (strcmp((const char *)self->method, "html") == 0) {
- RETVAL = "text/html";
- }
- else if (strcmp((const char *)self->method, "text") == 0) {
- RETVAL = "text/plain";
- }
- }
+ XSLT_GET_IMPORT_PTR(mediaType, self, mediaType);
+
+ if(mediaType == NULL) {
+ XSLT_GET_IMPORT_PTR(method, self, method);
+ RETVAL = "text/xml";
+ /* this below is rather simplistic, but should work for most cases */
+ if (method != NULL) {
+ if (strcmp(method, "html") == 0) {
+ RETVAL = "text/html";
+ }
+ else if (strcmp(method, "text") == 0) {
+ RETVAL = "text/plain";
+ }
}
}
+ else {
+ RETVAL = mediaType;
+ }
OUTPUT:
RETVAL
char *
output_encoding(self)
xsltStylesheetPtr self
+ PREINIT:
+ xmlChar *encoding;
CODE:
- RETVAL = (char *)self->encoding;
+ XSLT_GET_IMPORT_PTR(encoding, self, encoding)
+
+ RETVAL = encoding;
if (RETVAL == NULL) {
RETVAL = "UTF-8";
}