#!/usr/bin/perl -wT use strict; use XML::LibXML; use XML::LibXSLT; # Create XML Document my $dom = XML::LibXML::Document->createDocument('1.0'); my $root = $dom->createElement('categories'); $dom->setDocumentElement($root); #create cat element at append it to root for () { chomp; my ($id,$name,$parent) = split(/\,/,$_); my $elem = $dom->createElement('cat'); $elem->setAttribute('catid',$id); $elem->setAttribute('name',$name); $elem->setAttribute('parent',$parent); $root->appendChild($elem); } # Load and apply XSLT stylesheet my $xslt = XML::LibXSLT->new(); my $stylesheet = $xslt->parse_stylesheet_file('catnames.xsl'); my $results = $stylesheet->transform($dom); print $results->toString(1); __DATA__ 26,PWC,0 24,Truck,0 22,Snowmobile,0 30,Parts,22 31,Accessories,22 32,Off Road Bikes,0 33,Road Bikes,0 34,HJC,31 40,Reeds,26 41,Intake Grates,26 44,Accessories,24 98,Demo,40 99,Pop,98