Subject: Re: [xsl] When to use conditional constructions? From: "Abel Braaksma (Exselt)" <abel@xxxxxxxxxx> Date: Mon, 31 Mar 2014 19:15:06 +0200 |
On 31-3-2014 17:23, Graydon wrote: > On Sun, Mar 30, 2014 at 10:45:21AM -0700, Dimitre Novatchev scripsit: >> >> In my Balisage-2013 article "Programming in XPath 3.0" [1], I raised >> the need for an XPath "import clause". > Such a thing would be lovely. > > While we're extending XPath, can we have support for named, referenceable > predicate definitions? Preferably composable ones, so I can combine a > group of named predicates under another name? > > -- Graydon, who is going to be embarrassed if that's snuck into 3.0 > We have functions since XSLT 2.0. Perhaps not exactly the same, but you can create a function for your predicate, with a parameter for the current node and write: <xsl:template match="foo[my:referenced-predicate-function(.)]"> .... </xsl:template> In 3.0 you can assign function items to variables, allowing something like this: <xsl:variable name="predicates" as="function(*)*"> <xsl:sequence select=" function($a) { $a/local-name() = 'para' }, function($a) { $a/text() = 'hello world'}" /> </xsl:variable> <xsl:template match="*[some $f in $predicates satisfies $f(.)]"> <xsl:text>Found it!</xsl:text> </xsl:template> Whether this proves to be handy in practical scenarios, I am not sure. You can even apply-templates on any sequence, even non-nodes, in 3.0, allowing you to apply-templates on a sequence of function items, which may give you some kind of MVC container for XSLT, but again whether that is practical I don't know yet. There's also another feature possibly entering 3.0 that might be of help here (static AVTs), but whether or not it will make 3.0 is yet unclear. See public bug 24619: https://www.w3.org/Bugs/Public/show_bug.cgi?id=24619. Cheers, Abel Braaksma Exselt XSLT 3.0 processor http://exselt.net
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] When to use conditional c, Graydon | Thread | Re: [xsl] When to use conditional c, John Lumley |
Re: [xsl] When to use conditional c, Dimitre Novatchev | Date | Re: [xsl] When to use conditional c, Ihe Onwuka |
Month |