Permalink
Browse files

inner-xml

  • Loading branch information...
1 parent 678a5ca commit 6e2fba50a65202a740612c0d3e565800135a727a @fizx committed Oct 2, 2009
Showing with 56 additions and 33 deletions.
  1. +44 −23 functions.c
  2. +1 −0 functions.h
  3. +8 −8 libtool
  4. +1 −1 test/outer-xml.json
  5. +2 −1 test/outer-xml.let
View
@@ -1,3 +1,4 @@
+#include <stdbool.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/parserInternals.h>
@@ -22,33 +23,53 @@ void parsley_register_all(){
xsltHtmlDocumentFunction);
xsltRegisterExtModuleFunction ((const xmlChar *) "outer-xml", "http://parselets.com/stdlib",
xsltOuterXmlFunction);
+ xsltRegisterExtModuleFunction ((const xmlChar *) "inner-xml", "http://parselets.com/stdlib",
+ xsltInnerXmlFunction);
+}
+
+static void
+xsltStarXMLFunction(xmlXPathParserContextPtr ctxt, int nargs, bool is_inner) {
+ if (nargs != 1) {
+ xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
+ "outer-xml() : invalid number of args %d\n",
+ nargs);
+ ctxt->error = XPATH_INVALID_ARITY;
+ return;
+ }
+ if (ctxt->value->type == XPATH_NODESET) {
+ xmlXPathObjectPtr obj, newobj;
+
+ obj = valuePop(ctxt);
+
+ xmlBufferPtr buf = xmlBufferCreate();
+ int n = obj->nodesetval->nodeNr;
+ for(int i = 0; i < n; i++) {
+ xmlNodePtr node = obj->nodesetval->nodeTab[i];
+ xmlDocPtr doc = node->doc;
+ if(is_inner){
+ xmlNodePtr child = node->children;
+ while(child != NULL) {
+ xmlNodeDump(buf, doc, child, 0, 0);
+ child = child->next;
+ }
+ } else {
+ xmlNodeDump(buf, doc, node, 0, 0);
+ }
+ }
+ newobj = xmlXPathNewCString(xmlBufferContent(buf));
+ xmlBufferFree(buf);
+ valuePush(ctxt, newobj);
+ }
}
void
-xsltOuterXmlFunction(xmlXPathParserContextPtr ctxt, int nargs) {
- if (nargs != 1) {
- xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL,
- "outer-xml() : invalid number of args %d\n",
- nargs);
- ctxt->error = XPATH_INVALID_ARITY;
- return;
- }
- if (ctxt->value->type == XPATH_NODESET) {
- xmlXPathObjectPtr obj, newobj;
+xsltInnerXmlFunction(xmlXPathParserContextPtr ctxt, int nargs) {
+ xsltStarXMLFunction(ctxt, nargs, true);
+}
- obj = valuePop(ctxt);
-
- xmlBufferPtr buf = xmlBufferCreate();
- int n = obj->nodesetval->nodeNr;
- for(int i = 0; i < n; i++) {
- xmlNodePtr node = obj->nodesetval->nodeTab[i];
- xmlDocPtr doc = node->doc;
- xmlNodeDump(buf, doc, node, 0, 0);
- }
- newobj = xmlXPathNewCString(xmlBufferContent(buf));
- xmlBufferFree(buf);
- valuePush(ctxt, newobj);
- }
+void
+xsltOuterXmlFunction(xmlXPathParserContextPtr ctxt, int nargs) {
+ xsltStarXMLFunction(ctxt, nargs, false);
}
void
View
@@ -12,6 +12,7 @@ void parsley_register_all();
static void xsltHtmlDocumentFunction(xmlXPathParserContextPtr, int);
static void xsltHtmlDocumentFunctionLoadDocument(xmlXPathParserContextPtr, xmlChar*);
+static void xsltInnerXmlFunction(xmlXPathParserContextPtr ctxt, int nargs);
static void xsltOuterXmlFunction(xmlXPathParserContextPtr ctxt, int nargs);
xsltDocumentPtr xsltLoadHtmlDocument(xsltTransformContextPtr, const xmlChar *);
View
@@ -2,7 +2,7 @@
# libtool - Provide generalized library-building support services.
# Generated automatically by config.status (parsleyc) 1.0
-# Libtool was configured on host kyles-macbook.local:
+# Libtool was configured on host kyles-macbook:
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
#
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
@@ -56,13 +56,13 @@ fast_install=needless
# The host system.
host_alias=
-host=i386-apple-darwin9.8.0
-host_os=darwin9.8.0
+host=i386-apple-darwin10.0.0
+host_os=darwin10.0.0
# The build system.
build_alias=
-build=i386-apple-darwin9.8.0
-build_os=darwin9.8.0
+build=i386-apple-darwin10.0.0
+build_os=darwin10.0.0
# A sed program that does not truncate output.
SED="/usr/bin/sed"
@@ -80,7 +80,7 @@ EGREP="/usr/bin/grep -E"
FGREP="/usr/bin/grep -F"
# A BSD- or MS-compatible name lister.
-NM="/usr/bin/nm -p"
+NM="/usr/bin/nm"
# Whether we need soft or hard links.
LN_S="ln -s"
@@ -234,7 +234,7 @@ finish_eval=""
hardcode_into_libs=no
# Compile-time system search path for libraries.
-sys_lib_search_path_spec="/usr/lib/i686-apple-darwin9/4.0.1 /usr/lib /usr/lib/gcc/i686-apple-darwin9/4.0.1 /usr/local/lib"
+sys_lib_search_path_spec="/usr/lib/gcc/i686-apple-darwin10/4.2.1/x86_64 /usr/lib/i686-apple-darwin10/4.2.1 /usr/lib /usr/local/lib"
# Run-time system search path for libraries.
sys_lib_dlsearch_path_spec="/usr/local/lib /lib /usr/lib"
@@ -254,7 +254,7 @@ striplib="strip -x"
# The linker used to build libraries.
-LD="/usr/libexec/gcc/i686-apple-darwin9/4.0.1/ld"
+LD="/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld"
# Commands used to build an old-style archive.
old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$oldlib"
View
@@ -1 +1 @@
-{ "foo": "<p id=\"foo\">bar<\/p>", "both": [ "<p id=\"foo\">bar<\/p>", "<p id=\"foo\">baz<\/p>" ] }
+{ "foo": "<p id=\"foo\">bar<\/p>", "both": [ "<p id=\"foo\">bar<\/p>", "<p id=\"foo\">baz<\/p>" ], "inner": "<p id=\"foo\">bar<\/p><p id=\"foo\">baz<\/p>" }
View
@@ -1,4 +1,5 @@
{
"foo": "lib:outer-xml(p)",
- "both": [ "lib:outer-xml(p)" ]
+ "both": [ "lib:outer-xml(p)" ],
+ "inner": "lib:inner-xml(body)"
}

0 comments on commit 6e2fba5

Please sign in to comment.