Click here to get back home

Re: Ripping out parts of a DOM using XML::XSLT

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Re: Ripping out parts of a DOM using XML::XSLT Bjoern Hoehrmann 06-18-2008
Get Chitika Premium
Posted by Bjoern Hoehrmann on June 18, 2008, 4:53 am
Please log in for more thread options
* NiallBCarter wrote in comp.lang.perl.misc:
>I have this KML (Slightly abridged)
>
><?xml version="1.0" encoding="UTF-8"?>

These two specify the name of the element, that is, the tuple

{'http://earth.google.com/kml/2.0', 'kml'}

The parts are referred to as namespace name and local name.

><xsl:template match="/Document/Placemark">
><xsl:for-each select="kml/document/Placemark">

Here the 'kml' refers to just

{'', 'kml'}

Which is a different tuple. Also, the root element in your document is
this kml element, while your template match attribute looks for a root
element called 'Document'. To get the names right you have to either
declare a namespace prefix and use it in your XPath expressions ala

/kml:kml/kml:Document/...

or use predicates with the namespace-uri() and local-name() functions:

/*[local-name() = 'kml' and namespace-uri() = 'http://...']/...

Do note that there are more sophisticated XML/XSLT/XPath modules on
CPAN, XML::LibXSLT for example.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

Posted by NiallBCarter on June 18, 2008, 5:04 am
Please log in for more thread options
>
> {'', 'kml'}
>
> Which is a different tuple. Also, the root element in your document is
> this kml element, while your template match attribute looks for a root
> element called 'Document'. To get the names right you have to either
> declare a namespace prefix and use it in your XPath expressions ala
>
> /kml:kml/kml:Document/...
>
> or use predicates with the namespace-uri() and local-name() functions:
>
> /*[local-name() = 'kml' and namespace-uri() = 'http://...']/...
>

So would I be right in saying that it is not as simple as I thought?



> Do note that there are more sophisticated XML/XSLT/XPath modules on
> CPAN, XML::LibXSLT for example.

I am aware that there are more sophisticated modules but I experience
troubles with each one I try. It was suggested that I stick to
XML::XSLT for the moment and try to come up with a work around rather
than have to hassle the IT staff to install more modules on the
managed computer I work on.

Essentially all I want to do is strip out the <kml>, <Document> parts
and be left with a DOM containing <Placemark> and all contents </
Placemark>
Is there a simple way of doing this?

rgds,

Niall

Similar ThreadsPosted
xslt ? August 23, 2006, 4:07 pm
XSLT Transformation July 9, 2004, 1:28 pm
Perl XSLT module? September 9, 2004, 9:08 pm
[XML::XSLT] empty result while parsing xml file December 9, 2004, 1:50 pm
Issue with XML::XSLT and html encoded characters (á etc) April 13, 2006, 2:43 pm
XML::XSLT is no longer doing disable-output-escaping May 25, 2006, 6:25 pm
Grep in parts of an XML June 23, 2005, 12:48 am
deflate parts of a file June 29, 2006, 12:03 pm
date parts in one step June 20, 2007, 12:28 pm
remove unwanted parts from strings November 5, 2004, 4:20 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap