shithub: xmltools

ref: fc012e4dcc216d33f07262e64e3417043a7aa564
dir: /xslt.c/

View raw version
#include <u.h>
#include <libc.h>
#include <xml.h>
#include <xpath.h>

Xml *xml = nil;
Xml *style = nil;

void
usage(void)
{
	fprint(2, "usage: %s\n", argv0);
	exits(nil);
}

void
main(int argc, char **argv)
{
	int fd;
	char *s = nil;

	ARGBEGIN{
	case 'h':
		usage();
		break;
	case 's':
		s = EARGF(usage());
		break;
	}ARGEND;

	if (argc && *argv[0]) {
		fd = open(argv[0], OREAD);
		if (fd < 0)
			sysfatal("unable to open file: %r");
		xml = xmlparse(fd, 8192, 0);
		close(fd);
	} else {
		xml = xmlparse(0, 8192, 0);
	}

	xmldebug = 1;
	if (s) {
		fd = open(s, OREAD);
		if (fd < 0)
			sysfatal("unable to open file: %r");
		style = xmlparse(fd, 8192, 0);
		close(fd);
	}
	
	if (!style)
		sysfatal("err: %r");
	
	xmlprint(style, 2);
	
	Ns *ns;
	
	for (ns = style->ns; ns; ns = ns->next) {
		fprint(2, "ns: %s → %s\n", ns->name, ns->decl);
	}
}