mirror of
https://gitlab.gnome.org/GNOME/libxslt
synced 2025-12-03 16:31:12 +03:00
fixed bug #89258 and a bit of cleanup. added the example in the regression
* libxslt/transform.c libxslt/xslt.c: fixed bug #89258 and a bit of cleanup. * tests/docs/Makefile.am tests/docs/bug-90.xml tests/general/Makefile.am tests/general/bug-90.*: added the example in the regression tests for this case Daniel
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
Wed Aug 21 13:48:07 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* libxslt/transform.c libxslt/xslt.c: fixed bug #89258 and a bit of
|
||||||
|
cleanup.
|
||||||
|
* tests/docs/Makefile.am tests/docs/bug-90.xml
|
||||||
|
tests/general/Makefile.am tests/general/bug-90.*: added the
|
||||||
|
example in the regression tests for this case
|
||||||
|
|
||||||
Tue Aug 20 16:40:48 CEST 2002 Igor Zlatkovic <igor@stud.fh-frankfurt.de>
|
Tue Aug 20 16:40:48 CEST 2002 Igor Zlatkovic <igor@stud.fh-frankfurt.de>
|
||||||
|
|
||||||
* win32/Makefile.msvc: added the prefix location to the include
|
* win32/Makefile.msvc: added the prefix location to the include
|
||||||
|
|||||||
@@ -344,6 +344,7 @@ xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
|||||||
* @ctxt: a XSLT process context
|
* @ctxt: a XSLT process context
|
||||||
* @target: the element where the text will be attached
|
* @target: the element where the text will be attached
|
||||||
* @string: the text string
|
* @string: the text string
|
||||||
|
* @noescape: should disable-escaping be activated for this text node.
|
||||||
*
|
*
|
||||||
* Create a text node
|
* Create a text node
|
||||||
*
|
*
|
||||||
@@ -351,7 +352,7 @@ xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
|||||||
*/
|
*/
|
||||||
static xmlNodePtr
|
static xmlNodePtr
|
||||||
xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target,
|
xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target,
|
||||||
const xmlChar *string) {
|
const xmlChar *string, int noescape) {
|
||||||
xmlNodePtr copy;
|
xmlNodePtr copy;
|
||||||
|
|
||||||
if (string == NULL)
|
if (string == NULL)
|
||||||
@@ -363,14 +364,28 @@ xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target,
|
|||||||
string);
|
string);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO: handle coalescing of text nodes here */
|
/* handle coalescing of text nodes here */
|
||||||
if ((ctxt->type == XSLT_OUTPUT_XML) &&
|
if ((ctxt->type == XSLT_OUTPUT_XML) &&
|
||||||
(ctxt->style->cdataSection != NULL) &&
|
(ctxt->style->cdataSection != NULL) &&
|
||||||
(target != NULL) &&
|
(target != NULL) &&
|
||||||
(xmlHashLookup(ctxt->style->cdataSection,
|
(xmlHashLookup(ctxt->style->cdataSection,
|
||||||
target->name) != NULL)) {
|
target->name) != NULL)) {
|
||||||
|
if ((target != NULL) && (target->last != NULL) &&
|
||||||
|
(target->last->type == XML_CDATA_SECTION_NODE)) {
|
||||||
|
xmlNodeAddContent(target->last, string);
|
||||||
|
return(target->last);
|
||||||
|
}
|
||||||
copy = xmlNewCDataBlock(ctxt->output, string,
|
copy = xmlNewCDataBlock(ctxt->output, string,
|
||||||
xmlStrlen(string));
|
xmlStrlen(string));
|
||||||
|
} else if ((noescape) && (ctxt->type == XSLT_OUTPUT_XML)) {
|
||||||
|
if ((target != NULL) && (target->last != NULL) &&
|
||||||
|
(target->last->type == XML_TEXT_NODE) &&
|
||||||
|
(target->last->name == xmlStringTextNoenc)) {
|
||||||
|
xmlNodeAddContent(target->last, string);
|
||||||
|
return(target->last);
|
||||||
|
}
|
||||||
|
copy = xmlNewText(string);
|
||||||
|
copy->name = xmlStringTextNoenc;
|
||||||
} else {
|
} else {
|
||||||
if ((target != NULL) && (target->last != NULL) &&
|
if ((target != NULL) && (target->last != NULL) &&
|
||||||
(target->last->type == XML_TEXT_NODE) &&
|
(target->last->type == XML_TEXT_NODE) &&
|
||||||
@@ -2450,7 +2465,7 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
|||||||
"xsltCopyOf: result %s\n", res->stringval);
|
"xsltCopyOf: result %s\n", res->stringval);
|
||||||
#endif
|
#endif
|
||||||
/* append content as text node */
|
/* append content as text node */
|
||||||
xsltCopyTextString(ctxt, ctxt->insert, res->stringval);
|
xsltCopyTextString(ctxt, ctxt->insert, res->stringval, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2509,22 +2524,19 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
|||||||
if (res->type != XPATH_STRING)
|
if (res->type != XPATH_STRING)
|
||||||
res = xmlXPathConvertString(res);
|
res = xmlXPathConvertString(res);
|
||||||
if (res->type == XPATH_STRING) {
|
if (res->type == XPATH_STRING) {
|
||||||
/* TODO: integrate with xsltCopyTextString */
|
copy = xsltCopyTextString(ctxt, ctxt->insert, res->stringval,
|
||||||
copy = xmlNewText(res->stringval);
|
comp->noescape);
|
||||||
if (copy != NULL) {
|
|
||||||
if (comp->noescape)
|
|
||||||
copy->name = xmlStringTextNoenc;
|
|
||||||
xmlAddChild(ctxt->insert, copy);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ctxt->state = XSLT_STATE_STOPPED;
|
ctxt->state = XSLT_STATE_STOPPED;
|
||||||
}
|
}
|
||||||
if (copy == NULL) {
|
if (copy == NULL) {
|
||||||
|
if ((res == NULL) || (res->stringval != NULL)) {
|
||||||
xsltPrintErrorContext(ctxt, NULL, inst);
|
xsltPrintErrorContext(ctxt, NULL, inst);
|
||||||
xsltGenericError(xsltGenericErrorContext,
|
xsltGenericError(xsltGenericErrorContext,
|
||||||
"xsltValueOf: text copy failed\n");
|
"xsltValueOf: text copy failed\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef WITH_XSLT_DEBUG_PROCESS
|
#ifdef WITH_XSLT_DEBUG_PROCESS
|
||||||
else
|
else
|
||||||
xsltGenericDebug(xsltGenericDebugContext,
|
xsltGenericDebug(xsltGenericDebugContext,
|
||||||
|
|||||||
@@ -1764,6 +1764,7 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
|
|||||||
break;
|
break;
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* process other top-level elements
|
* process other top-level elements
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ EXTRA_DIST = \
|
|||||||
bug-87.xml \
|
bug-87.xml \
|
||||||
bug-88.xml \
|
bug-88.xml \
|
||||||
bug-89.xml \
|
bug-89.xml \
|
||||||
|
bug-90.xml \
|
||||||
character.xml \
|
character.xml \
|
||||||
array.xml \
|
array.xml \
|
||||||
items.xml
|
items.xml
|
||||||
|
|||||||
15
tests/docs/bug-90.xml
Normal file
15
tests/docs/bug-90.xml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
============================================================
|
||||||
|
This is the input XML
|
||||||
|
============================================================
|
||||||
|
-->
|
||||||
|
<fruit-sites>
|
||||||
|
<fruit type="apples">
|
||||||
|
<site><![CDATA[http://www.apples.com/site?args&stuff]]>
|
||||||
|
</site>
|
||||||
|
</fruit>
|
||||||
|
<fruit type="pears">
|
||||||
|
<site>http://www.pears.com/index.html</site>
|
||||||
|
</fruit>
|
||||||
|
</fruit-sites>
|
||||||
@@ -92,6 +92,7 @@ EXTRA_DIST = \
|
|||||||
bug-87.out bug-87.xsl \
|
bug-87.out bug-87.xsl \
|
||||||
bug-88.out bug-88.xsl \
|
bug-88.out bug-88.xsl \
|
||||||
bug-89.out bug-89.xsl \
|
bug-89.out bug-89.xsl \
|
||||||
|
bug-90.out bug-90.xsl \
|
||||||
character.out character.xsl \
|
character.out character.xsl \
|
||||||
character2.out character2.xsl \
|
character2.out character2.xsl \
|
||||||
itemschoose.out itemschoose.xsl \
|
itemschoose.out itemschoose.xsl \
|
||||||
|
|||||||
17
tests/general/bug-90.out
Normal file
17
tests/general/bug-90.out
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<new-fruit1 type="apples">
|
||||||
|
<![CDATA[
|
||||||
|
The site is at
|
||||||
|
http://www.apples.com/site?args&stuff
|
||||||
|
]]>
|
||||||
|
</new-fruit1><new-fruit2 type="apples"><![CDATA[
|
||||||
|
The site is at http://www.apples.com/site?args&stuff
|
||||||
|
]]></new-fruit2>
|
||||||
|
<new-fruit1 type="pears">
|
||||||
|
<![CDATA[
|
||||||
|
The site is at
|
||||||
|
http://www.pears.com/index.html]]>
|
||||||
|
</new-fruit1><new-fruit2 type="pears"><![CDATA[
|
||||||
|
The site is at http://www.pears.com/index.html]]></new-fruit2>
|
||||||
|
|
||||||
35
tests/general/bug-90.xsl
Normal file
35
tests/general/bug-90.xsl
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<!--
|
||||||
|
============================================================
|
||||||
|
This is a stylesheet that will create, for each input <fruit> element,
|
||||||
|
two output elements - <new-fruit1> and <new-fruit2> , each of
|
||||||
|
which should wrap the content of the the input fruit/site element
|
||||||
|
in a CDATA block.
|
||||||
|
<new-fruit1> does this 'properly' via cdata-section-elements
|
||||||
|
<new-fruit2> does it with a workaround named template 'wrap-cdata'
|
||||||
|
============================================================
|
||||||
|
-->
|
||||||
|
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
|
||||||
|
<xsl:output method="xml" cdata-section-elements="new-fruit1" indent="yes"/>
|
||||||
|
<xsl:template match="fruit-sites/fruit">
|
||||||
|
<new-fruit1 type="{@type}">
|
||||||
|
The site is at
|
||||||
|
<xsl:value-of select="./site"/>
|
||||||
|
</new-fruit1>
|
||||||
|
<new-fruit2 type="{@type}">
|
||||||
|
<xsl:call-template name="wrap-cdata">
|
||||||
|
<xsl:with-param name="content">
|
||||||
|
The site is at <xsl:value-of select="./site"/>
|
||||||
|
</xsl:with-param>
|
||||||
|
</xsl:call-template>
|
||||||
|
</new-fruit2>
|
||||||
|
</xsl:template>
|
||||||
|
|
||||||
|
<!-- Wrap $content in a CDATA block -->
|
||||||
|
<xsl:template name="wrap-cdata">
|
||||||
|
<xsl:param name="content"/>
|
||||||
|
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text> <!--
|
||||||
|
--><xsl:value-of disable-output-escaping="yes" select="$content"/> <!--
|
||||||
|
--><xsl:text disable-output-escaping="yes">]]></xsl:text>
|
||||||
|
</xsl:template>
|
||||||
|
</xsl:stylesheet>
|
||||||
Reference in New Issue
Block a user