Re: namespace prefixes in XSLT parameters

Bruce R Miller <[email protected]> Wed, 19 Sep 2012 14:49:06 -0400
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On 09/19/2012 04:48 AM, Daniel Perrett wrote:
>  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?)

Yeah, sure, but since passing in the parameter is very much as if I had replaced
   <xsl:param name="PARAM">novalue</xsl:param>
with
   <xsl:param name="PARAM" select="//what:ever/x:path/expression()"/>
in the stylesheet source,  you might reasonably think that the namespaces
and prefixes defined at that point lexically, would be in effect without
any violation of modularity.

Of course, parameters & namespaces were all pretty
much dangling as far as XPath 1.0 is concerned.

However, in that case, there ought to be corresponding registration
functions, as with XPathContext.

> 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.

Yeah, Yuck.  It may come to that, though.

Thanks for your thoughts;
bruce

> 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 <http://listserv.activestate.com/mailman/mysubs>
>

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs