W3C home > Mailing lists > Public > public-xml-processing-model-wg@w3.org > April 2007

Re: Proposed component: p:string-replace

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 23 Apr 2007 20:43:59 +0100
Message-ID: <462D0C7F.4090500@jenitennison.com>
To: public-xml-processing-model-wg@w3.org

Norman Walsh wrote:
> I propose the following component for our standard library:
> 
>   <p:declare-step type="p:string-replace">
>     <p:input port="source" sequence="no"/>
>     <p:output port="result" sequence="no"/>
>     <p:option name="match" required="yes"/>
>     <p:option name="replace" required="yes"/>
>   </p:declare-step>
> 
> This step searches for nodes that match the XPath match pattern in the
> "match" option and replaces the string value of the matched node with
> the value of the replace option. The replace option is an XPath 1.0
> expression that will be evaluated with the context node set to the
> matching node and the XPath variable $p:string set to the original
> value of the node.

If the context node is the matching node, then using . or string() will 
give you the original value of the node. I don't see the need for the 
binding of $p:string.

> For example, this would replace the name of the p:identity step
> named 'foo' with 'FOO'.
> 
> <px:string-replace>
>   <p:option name="match" value="p:identity[@name='foo']/@name"/>
>   <p:option name="replace" value="translate($p:string,'abcdefghijklmnopqrstuvwyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
> </px:string-replace>

You could do:

<px:string-replace>
   <p:option name="match" value="p:identity[@name='foo']/@name"/>
   <p:option name="replace" 
value="translate(.,'abcdefghijklmnopqrstuvwyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
</px:string-replace>

Jeni
-- 
Jeni Tennison
http://www.jenitennison.com
Received on Monday, 23 April 2007 19:44:06 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 8 January 2008 14:21:50 GMT