This sounds like a good candidate for XML::LibXML and XML::LibXSLT.

UPDATE:
First off, i really think you should change the structure of your XML to something like: def.xml

<book> <chapter id="1"> <part id="1"> <info>infoinfostuffhere</info> <def word="someword">some definition of the word</def> <extra>more info and notes</extra> </part> <part id="2"> <info>infoinfostuffhere</info> <def word="someword">some definition of the word</def> <extra>more info and notes</extra> </part> </chapter> </book>
This will make parsing much easier ... having a bunch of <section id="foo"> tags is just too general. Also, be sure and wrap everything you can. Now that we have some, IMHO, better XML to work with, we can define a stylesheet: def.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Tr +ansform"> <xsl:template match = "/book" > <xsl:for-each select = "chapter[@id]" > <h1> Chapter <xsl:value-of select="@id"/> </h1> <xsl:for-each select = "part[@id]" > <h3> Part <xsl:value-of select="@id"/> </h3> <i><xsl:value-of select="info"/></i><br/> <xsl:for-each select = "def[@word]" > <b><u><xsl:value-of select="@word"/></u></b>:<br/> </xsl:for-each> <xsl:value-of select="def"/><br/> <xsl:value-of select="extra"/><br/> </xsl:for-each> </xsl:for-each> </xsl:template> </xsl:stylesheet>
And finally, the script to transform all of this into 'HTML'
use strict; use warnings; use XML::LibXML; use XML::LibXSLT; my $xml = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); my $source = $xml->parse_file('def.xml'); my $style_doc = $xml->parse_file('def.xsl'); my $stylesheet = $xslt->parse_stylesheet($style_doc); my $results = $stylesheet->transform($source); print $stylesheet->output_string($results);

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Picking an XML Module by jeffa
in thread Picking an XML Module by ninja-joe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.