Re: namespace prefixes in XSLT parameters
Daniel Perrett <[email protected]> Wed, 19 Sep 2012 09:48:06 +0100
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <OFE237699D.EFF91298-ON80257A7E.002EFC17-80257A7E.003049BF@cambridge.org> |
>From what I understand of the dark art of namespaces, this makes a certain amount of sense - the spreadsheet should function identically to the outside whether it internally represents "http://example.com/ltx":section as ltx:section or as l:section. Namespace prefixes are, for the purpose of the stylesheet, local variables. This means that you should not be able to rely on namespace prefixes declared inside the stylesheet, that would violate encapsulation. (although are doesn't passing an xpath query to be evaluated also count as violating encapsulation?) I would create a function that turns your xpath expression with namespace prefixes into one with fully qualified namespaces. It'd be pretty simple to put one together with regexes, but there would be edge cases like text()[.="ltx:section"], although these may be so unlikely you might not mind. LibXML also might have some tools for doing this, but I'm not sure what. Daniel From: Bruce R Miller <[email protected]> To: "[email protected]" <[email protected]> Date: 19/09/2012 00:10 Subject: namespace prefixes in XSLT parameters Sent by: [email protected] Hi all; 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? 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!) And there seems to be no methods to register such associations. Googling turns up an ancient email that establishes that XPathContext and LibXSLT are entirely disconnected.... Is there a way to use namespace prefixes? Thanks; bruce _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs