Skip to content
Snippets Groups Projects
Commit 48a07afb6c1b authored by Daniel Veillard's avatar Daniel Veillard
Browse files

./xsltproc doc.xsl doc.xml start giving interesting stuff:

- transform.c, xsltproc.c: small fight with spaces and formatting
  may need a revisit later but looks pretty good right now.
Daniel
parent 98ddb4e13c1e
Branches
Tags
No related merge requests found
Fri Jan 12 18:34:01 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* transform.c, xsltproc.c: small fight with spaces and formatting
may need a revisit later but looks pretty good right now.
Fri Jan 12 13:43:30 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr> Fri Jan 12 13:43:30 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* transform.c: basic processing in place * transform.c: basic processing in place
......
...@@ -139,6 +139,65 @@ ...@@ -139,6 +139,65 @@
void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node); void xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node);
/** /**
* xsltCopyNode:
* @ctxt: a XSLT process context
* @node: the element node in the source tree.
* @insert: the parent in the result tree.
*
* Make a copy of the element node @node
* and insert it as last child of @insert
*
* Returns a pointer to the new node, or NULL in case of error
*/
xmlNodePtr
xsltCopyNode(xsltTransformContextPtr ctxt, xmlNodePtr node,
xmlNodePtr insert) {
xmlNodePtr copy;
copy = xmlCopyNode(node, 0);
if (copy != NULL) {
xmlAddChild(insert, copy);
/*
* Add namespaces as they are needed
*/
if (node->nsDef != NULL)
copy->nsDef = xmlCopyNamespaceList(node->nsDef);
if (node->ns != NULL) {
/*
* optimization, if the namespace is already the
* on on the parent node, reuse it directly
*
* TODO: check possible mess with xmlCopyNamespaceList
*/
if ((insert->type == XML_ELEMENT_NODE) &&
(insert->ns != NULL) &&
(xmlStrEqual(insert->ns->href, node->ns->href))) {
copy->ns = insert->ns;
} else {
xmlNsPtr ns;
/*
* Look in the output tree if the namespace is
* already in scope.
*/
ns = xmlSearchNsByHref(ctxt->output, copy,
node->ns->href);
if (ns != NULL)
copy->ns = ns;
else {
ns = xmlNewNs(copy, node->ns->href,
node->ns->prefix);
}
}
}
} else {
xsltGenericError(xsltGenericErrorContext,
"xsltProcessOneNode: copy %s failed\n", node->name);
}
return(copy);
}
/**
* xsltDefaultProcessOneNode: * xsltDefaultProcessOneNode:
* @ctxt: a XSLT process context * @ctxt: a XSLT process context
* @node: the node in the source tree. * @node: the node in the source tree.
...@@ -147,7 +206,18 @@ ...@@ -147,7 +206,18 @@
* <xsl:template match="*|/"> * <xsl:template match="*|/">
* <xsl:apply-templates/> * <xsl:apply-templates/>
* </xsl:template> * </xsl:template>
*
* and
*
* <xsl:template match="text()|@*">
* <xsl:value-of select="."/>
* </xsl:template>
*
* Note also that namespaces declarations are copied directly:
*
* the built-in template rule is the only template rule that is applied
* for namespace nodes.
*/ */
void void
xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
xmlNodePtr copy; xmlNodePtr copy;
...@@ -150,7 +220,8 @@ ...@@ -150,7 +220,8 @@
*/ */
void void
xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) {
xmlNodePtr copy; xmlNodePtr copy;
switch (node->type) { switch (node->type) {
case XML_DOCUMENT_NODE: case XML_DOCUMENT_NODE:
case XML_HTML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE:
...@@ -169,5 +240,14 @@ ...@@ -169,5 +240,14 @@
break; break;
case XML_TEXT_NODE: case XML_TEXT_NODE:
/* TODO: check the whitespace stripping rules ! */ /* TODO: check the whitespace stripping rules ! */
if (IS_BLANK_NODE(node)) if ((IS_BLANK_NODE(node)) &&
(node->parent != NULL) &&
(ctxt->style->stripSpaces != NULL)) {
const xmlChar *val;
val = (const xmlChar *)
xmlHashLookup(ctxt->style->stripSpaces,
node->parent->name);
if ((val != NULL) &&
(xmlStrEqual(val, (xmlChar *) "strip")))
break; break;
...@@ -173,7 +253,9 @@ ...@@ -173,7 +253,9 @@
break; break;
}
/* no break on purpose */
case XML_CDATA_SECTION_NODE: case XML_CDATA_SECTION_NODE:
copy = xmlCopyNode(node, 0); copy = xmlCopyNode(node, 0);
if (copy != NULL) { if (copy != NULL) {
xmlAddChild(ctxt->insert, copy); xmlAddChild(ctxt->insert, copy);
} else { } else {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
...@@ -174,10 +256,10 @@ ...@@ -174,10 +256,10 @@
case XML_CDATA_SECTION_NODE: case XML_CDATA_SECTION_NODE:
copy = xmlCopyNode(node, 0); copy = xmlCopyNode(node, 0);
if (copy != NULL) { if (copy != NULL) {
xmlAddChild(ctxt->insert, copy); xmlAddChild(ctxt->insert, copy);
} else { } else {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
"xsltProcessOneNode: text copy failed\n"); "xsltDefaultProcessOneNode: text copy failed\n");
} }
break; break;
default: default:
...@@ -260,6 +342,12 @@ ...@@ -260,6 +342,12 @@
#endif #endif
TODO TODO
} }
} else if (!(IS_BLANK_NODE(cur))) { } else if (cur->type == XML_TEXT_NODE) {
/*
* This text comes from the stylesheet
* For stylesheets, the set of whitespace-preserving
* element names consists of just xsl:text.
*/
if (!(IS_BLANK_NODE(cur))) {
#ifdef DEBUG_PROCESS #ifdef DEBUG_PROCESS
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
...@@ -264,9 +352,9 @@ ...@@ -264,9 +352,9 @@
#ifdef DEBUG_PROCESS #ifdef DEBUG_PROCESS
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
"xsltProcessOneNode: copy %s\n", cur->name); "xsltProcessOneNode: copy text %s\n", cur->content);
#endif #endif
copy = xmlCopyNode(cur, 0); copy = xmlCopyNode(cur, 0);
if (copy != NULL) { if (copy != NULL) {
xmlAddChild(insert, copy); xmlAddChild(insert, copy);
} else { } else {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
...@@ -267,9 +355,9 @@ ...@@ -267,9 +355,9 @@
#endif #endif
copy = xmlCopyNode(cur, 0); copy = xmlCopyNode(cur, 0);
if (copy != NULL) { if (copy != NULL) {
xmlAddChild(insert, copy); xmlAddChild(insert, copy);
} else { } else {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,
"xsltProcessOneNode: copy %s failed\n", cur->name); "xsltProcessOneNode: text copy failed\n");
return; }
} }
...@@ -275,4 +363,16 @@ ...@@ -275,4 +363,16 @@
} }
} else {
#ifdef DEBUG_PROCESS
xsltGenericError(xsltGenericErrorContext,
"xsltProcessOneNode: copy node %s\n", cur->name);
#endif
copy = xsltCopyNode(ctxt, cur, insert);
/*
* all the attributes are directly inherited
* TODO: Do the substitution of {} XPath expressions !!!
*/
if (cur->properties != NULL)
copy->properties = xmlCopyPropList(copy, cur->properties);
} }
/* /*
* Skip to next node * Skip to next node
...@@ -305,6 +405,13 @@ ...@@ -305,6 +405,13 @@
} }
} while (cur != NULL); } while (cur != NULL);
} }
/********
if (ctxt->style->indent) {
copy = xmlNewText("\n");
if (copy != NULL)
xmlAddChild(ctxt->insert, copy);
}
********/
} }
/** /**
......
...@@ -31,7 +31,12 @@ ...@@ -31,7 +31,12 @@
for (i = 1; i < argc ; i++) { for (i = 1; i < argc ; i++) {
if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) { if ((argv[i][0] != '-') || (strcmp(argv[i], "-") == 0)) {
cur = xsltParseStylesheetFile((const xmlChar *)argv[i]); cur = xsltParseStylesheetFile((const xmlChar *)argv[i]);
if (cur != NULL) {
if (cur->indent)
xmlIndentTreeOutput = 1;
else
xmlIndentTreeOutput = 0;
i++; i++;
break; break;
} }
} }
...@@ -34,7 +39,8 @@ ...@@ -34,7 +39,8 @@
i++; i++;
break; break;
} }
} }
}
for (;i < argc ; i++) { for (;i < argc ; i++) {
doc = xmlParseFile(argv[i]); doc = xmlParseFile(argv[i]);
if (doc == NULL) { if (doc == NULL) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment