Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: one script, not twelve nearly identical ones!

by bronto (Priest)
on Aug 25, 2004 at 17:12 UTC ( [id://385750]=note: print w/replies, xml ) Need Help??


in reply to one script, not twelve nearly identical ones!

If I well understand what your needs are, and you like perl (I believe so :-), you could consider using XML::XPathScript. XPathScript is a stylesheet language based on Perl and (guess that!) XPath. You can write different declarative templates a-la-XSLT for each XML "dialect" you use, or do more complex elaborations with perl subroutines, and let the xpathscript program to the job.

For (stupid) example, if you have an XML file like this:

<?xml version="1.0"?> <a> <b>Something</b> </a>

and this stylesheet:

<% $t->{a}{pre} = '<html><head><title>my page</title></head>' ; $t->{a}{post} = '</html>' ; $t->{b}{pre} = '<body><h1>' ; $t->{b}{post} = '</h1></body>' ; %> <%= apply_templates() %>

you must simply run xpathscript temp.xml temp.xps to get:

<html><head><title>my page</title></head> <body><h1>Something</h1></body> </html>

Anyway, you can do much, much more with XPathScript. I recommend to take a peek at the documentation on CPAN and give it a try!

PS: Of course, XPathScript stylesheets are modular, so that you could import common HTML parts (like headers and footers) from subsheets into all the ones that are specific for a certain job

Ciao!
--bronto


The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385750]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-29 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found