Re: Proposed component: p:string-replace

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 UTC