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>
|
||||
|
||||
* 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
|
||||
* @target: the element where the text will be attached
|
||||
* @string: the text string
|
||||
* @noescape: should disable-escaping be activated for this text node.
|
||||
*
|
||||
* Create a text node
|
||||
*
|
||||
@@ -351,7 +352,7 @@ xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
*/
|
||||
static xmlNodePtr
|
||||
xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target,
|
||||
const xmlChar *string) {
|
||||
const xmlChar *string, int noescape) {
|
||||
xmlNodePtr copy;
|
||||
|
||||
if (string == NULL)
|
||||
@@ -363,14 +364,28 @@ xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target,
|
||||
string);
|
||||
#endif
|
||||
|
||||
/* TODO: handle coalescing of text nodes here */
|
||||
/* handle coalescing of text nodes here */
|
||||
if ((ctxt->type == XSLT_OUTPUT_XML) &&
|
||||
(ctxt->style->cdataSection != NULL) &&
|
||||
(target != NULL) &&
|
||||
(xmlHashLookup(ctxt->style->cdataSection,
|
||||
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,
|
||||
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 {
|
||||
if ((target != NULL) && (target->last != NULL) &&
|
||||
(target->last->type == XML_TEXT_NODE) &&
|
||||
@@ -2450,7 +2465,7 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
"xsltCopyOf: result %s\n", res->stringval);
|
||||
#endif
|
||||
/* append content as text node */
|
||||
xsltCopyTextString(ctxt, ctxt->insert, res->stringval);
|
||||
xsltCopyTextString(ctxt, ctxt->insert, res->stringval, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -2509,22 +2524,19 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node,
|
||||
if (res->type != XPATH_STRING)
|
||||
res = xmlXPathConvertString(res);
|
||||
if (res->type == XPATH_STRING) {
|
||||
/* TODO: integrate with xsltCopyTextString */
|
||||
copy = xmlNewText(res->stringval);
|
||||
if (copy != NULL) {
|
||||
if (comp->noescape)
|
||||
copy->name = xmlStringTextNoenc;
|
||||
xmlAddChild(ctxt->insert, copy);
|
||||
}
|
||||
copy = xsltCopyTextString(ctxt, ctxt->insert, res->stringval,
|
||||
comp->noescape);
|
||||
}
|
||||
} else {
|
||||
ctxt->state = XSLT_STATE_STOPPED;
|
||||
}
|
||||
if (copy == NULL) {
|
||||
if ((res == NULL) || (res->stringval != NULL)) {
|
||||
xsltPrintErrorContext(ctxt, NULL, inst);
|
||||
xsltGenericError(xsltGenericErrorContext,
|
||||
"xsltValueOf: text copy failed\n");
|
||||
}
|
||||
}
|
||||
#ifdef WITH_XSLT_DEBUG_PROCESS
|
||||
else
|
||||
xsltGenericDebug(xsltGenericDebugContext,
|
||||
|
||||
@@ -1764,6 +1764,7 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) {
|
||||
break;
|
||||
cur = cur->next;
|
||||
}
|
||||
|
||||
/*
|
||||
* process other top-level elements
|
||||
*/
|
||||
|
||||
@@ -89,6 +89,7 @@ EXTRA_DIST = \
|
||||
bug-87.xml \
|
||||
bug-88.xml \
|
||||
bug-89.xml \
|
||||
bug-90.xml \
|
||||
character.xml \
|
||||
array.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-88.out bug-88.xsl \
|
||||
bug-89.out bug-89.xsl \
|
||||
bug-90.out bug-90.xsl \
|
||||
character.out character.xsl \
|
||||
character2.out character2.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