- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Wed, 1 Oct 2008 17:55:06 +0100
- To: Florent Georges <fgeorges@fgeorges.org>
- Cc: "Norman Walsh" <ndw@nwalsh.com>, "XProc Dev" <xproc-dev@w3.org>
Florent, On 1 Oct 2008, at 12:50, Florent Georges wrote: > If I am right, I've seen in another context that same > thing (quoting an XPath expression itself to pass it to a > step), but I can't find it anymore. Something like: > > xpath=" '/root/elem[@a eq 1]' " > > Of course, defining an attribute's value as an XPath > expression, thus having to quote string literals in that > context, is not at all disturbing (IMHO.) There are some steps that take XPaths or XSLT patterns as options. For example, p:string-replace has two options: match is an XSLT match pattern and replace is an XPath expression. So you can do something like: <p:string-replace match="/a/b[@c = 1]" replace="@d" /> which would replace the values of the <b> elements whose 'c' attribute was '1' with the values of their 'd' attribute. Now if you use <p:with-option>, the values of the 'match' and 'replace' options are set using an XPath expression. The options are set to strings that happen to be XSLT match patterns and XPath expressions. So you'd have to use the quotes around them: <p:string-replace> <p:with-option name="match" select="'/a/b[@c = 1]'" /> <p:with-option name="replace" select="'@d'" /> </p:string-replace> I agree that this looks insane, and when people are learning XProc they are going to forget the quotes, just like people forget to put quotes around strings when they set variables with the select attribute. I've lost count of the number of times I've written: <xsl:variable name="lowercase" select="abcdefghijklmnopqrstuvwxyz" /> But (a) if you want to set the option to a static string, you will want to use the shorthand notation anyway and (b) this allows you to set the value of the match and replace options based on information that you find within an XML document. Say that you had a configuration document like: <config> <elements>/a/b[@c = 1]</elements> <attribute>@d</attribute> </config> You could use this document to configure your XProc pipeline, by doing: <p:string-replace> <p:with-option name="match" select="/config/elements"> <p:document href="config.xml" /> </p:with-option> <p:with-option name="replace" select="/config/attribute"> <p:document href="config.xml" /> </p:with-option> </p:string-replace> In this scenario, the match option is set to an XSLT match pattern, and the XSLT match pattern comes from the config document. Locating the XSLT match pattern from the config document is done with an XPath expression. Similarly, the replace option is set to an XPath expression by selecting the XPath expression from the config document, using an XPath expression! See, it all makes absolute sense ;) Jeni -- Jeni Tennison http://www.jenitennison.com
Received on Wednesday, 1 October 2008 16:55:42 UTC