Re: namespace prefixes in XSLT parameters
Michael Ludwig <[email protected]> Sun, 23 Sep 2012 21:37:49 +0200
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <20120923193749.GC4724@Dago> |
Bruce R Miller schrieb am 18.09.2012 um 19:10 (-0400): > When you pass a parameter to an xslt, for me > the common issue was always to quote it enough, > since the value is actually an XPath expression: > $stylesheet->transform($document,PARAM=>"'some text'"); > > I thought I'd get fancy and try using the XPath > functionality. I guess it's clear that the XPath > will be _evaluated_ inside the stylesheet, and > with the document loaded --- otherwise, it wouldn't > be much use, right? I'm surprised. I used to think that wasn't possible. But it is: my $xslt = XML::LibXSLT->new; my $proc = $xslt->parse_stylesheet( $xsl_dom ); my $rslt = $proc->transform( $xml_dom, p => '//drei' ); # 'node()' And it also works from the command line using straight xsltproc: xsltproc --param p '//text()' x.xsl x.xml That's not possible using Java Xalan or Saxon 6.5 or 9.2. Offering this feature, in addition to being handy, does not seem to be bon-conformant: http://www.w3.org/TR/xslt#variables > For example: > $stylesheet->transform($document,PARAM=>"//ltx:section/ltx:title/text()"); > > What I hadn't anticipated is that it seems to > get _compiled_ before or outside that context. > In particular, it doesn't know the namespace prefixes > that have been established by the stylesheet > (nor by the document!) Exactly. Guess it's like when using an XML::LibXML::XPathContext on an XML::LibXML::Document. You'd have to $xpc->registerNs($prefix, $ns_uri) what you intend to use. > And there seems to be no methods to register such > associations. Exactly. There doesn't seem to be a documented way of doing so. No idea how hard it would be to add this feature. On the other hand, I've never used namespaced parameters, though I seem to remember they've been recommended to me for use in stylesheets that you intend to *distribute* to work as part of some customer's workflow. But I've never gotten that far in the first place … -- Michael Ludwig _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs