ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-xml
perl-xml
XML::LibXSLT callbacks - trying to "fake" the namespace prefix
by Randal L. Schwartz other posts by this author
Feb 27 2006 5:49AM messages near this date
view in the new Beta List Site
Re: XML::LibXML parser and external entity expansion? | Re: XML::LibXSLT callbacks - trying to "fake" the namespace prefix
& XSLT From what I've understood and test so far, I can successfully say:

    $xslt-> register_function('urn:foo', 'self', sub { warn Dumper(\@_) });

to register my "self" function in the "urn:foo" namespace, and then
in my template:

    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:foo="urn:foo"
                    xmlns="http://www.w3.org/TR/xhtml1/strict"
    > 

to let xslt know that the "foo:" prefix is really my "urn:foo",
and then:

    <xsl:value-of select="foo:self(3, 4, 5)"/> 

to invoke my callback.  Fine.  This works, mostly because I copied
it, only halfway understanding it, directly from the examples.

But here's the kicker... I'd like to avoid the middle step there.
The XSLT files are only partially under my control, and having someone
remember to add that hokey "xmlns:foo='urn:foo'" might be problematic,
although getting them to type "foo:self" will be mostly a matter
of programming by example.

Is there some step I can add, perhaps to add an attribute
to the xsl:stylesheet node between the time that I parse the stylesheet
doc and when I hand it to the XSLT processor, that will do what I want?
Or is there a better way to register that "self(3, 4, 5)" just "works"
with register_function?

I'm just trying to keep it streamlined for XSLT writers here.

I suppose in the 15 minutes it took for me to write this email,
I could have written

        my $s = $stylesheet_doc-> findnodes("//xsl:stylesheet")->[0];
        $s-> addChild(... something that makes up an attribute ...);

and tried it out, but is this too late to do by the time the sheet
is parsed?  Am I barking up the wrong tree?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@[...].com>  <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Kevin
A. Pagaltzis
Randal L. Schwartz
A. Pagaltzis

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved