[xquery-talk] renaming single attributes

Jason Hunter jhunter at xquery.com
Mon Jun 20 15:02:03 PDT 2005


> What's the easiest and/or most concise way of effecting a transformation
> that renames a single named attribute, if present, and leaves everything
> else the same?  For example, I might want to rename every occurrence of
> @att3 (two instances below) as @NEW-att3. Here's some sample "before" data:
> 
>     <record att1="att1" att3="att3" att4="att4">content1</record>
>     <record att3="att3" att4="att4">content2</record>
>     <record att4="att4" att5="att5">content3</record>
> 
> Here's the "after" version of the same. Note that all nodes except @att3
> remains the same:
> 
>     <record att1="att1" NEW-att3="att3" att4="att4">content1</record>
>     <record NEW-att3="att3" att4="att4">content2</record>
>     <record att4="att4" att5="att5">content3</record>
> 
> What's the simplest document tranformation that will accomplish this goal?
> Howard

As I know you've been using MarkLogic Server for some of your work, 
here's how you'd do it there:

for $att3 in $doc//@att3
return
xdmp:node-replace($att3, attribute { "NEW-att3" } { string($att3) })

-jh-



More information about the talk mailing list