Command xaddattribute



Name

xaddattribute Adds attributes to matching elements


Synopsis

addattribute match-expression attribute-name attribute-value

Options


match-expressionA XSLT style match expression
attribute-nameName of attribute to add or replace
attribute-valueValue of attribute



Description


addattribute is a simple front end to the xed command which adds or replaces a single attribute to all matching nodes.
The match-expression is an XSLT2.0 match expression. For all element nodes matching that expression, an attribute is added or replaced (if an attribute exists by the same name).


Example: add a comment attribute to all file elements produced by xls
xls | xaddattribute file comment "This is a file"


Result (when run on root xmlsh directory)

<dir>
  <file name="README.txt" path="C:/Work/DEI/xmlsh/trunk/README.txt" comment="This is a file"/>
  <file name="_dist" path="C:/Work/DEI/xmlsh/trunk/_dist" comment="This is a file"/>
  <file name="_out" path="C:/Work/DEI/xmlsh/trunk/_out" comment="This is a file"/>
  <file name="bin" path="C:/Work/DEI/xmlsh/trunk/bin" comment="This is a file"/>
  <file name="build-lib" path="C:/Work/DEI/xmlsh/trunk/build-lib" comment="This is a file"/>
  <file name="build.xml" path="C:/Work/DEI/xmlsh/trunk/build.xml" comment="This is a file"/>
  <file name="doc" path="C:/Work/DEI/xmlsh/trunk/doc" comment="This is a file"/>
  <file name="lib" path="C:/Work/DEI/xmlsh/trunk/lib" comment="This is a file"/>
  <file name="license.txt" path="C:/Work/DEI/xmlsh/trunk/license.txt" comment="This is a file"/>
  <file name="notices" path="C:/Work/DEI/xmlsh/trunk/notices" comment="This is a file"/>
  <file name="play" path="C:/Work/DEI/xmlsh/trunk/play" comment="This is a file"/>
  <file name="samples" path="C:/Work/DEI/xmlsh/trunk/samples" comment="This is a file"/>
  <file name="schemas" path="C:/Work/DEI/xmlsh/trunk/schemas" comment="This is a file"/>
  <file name="src" path="C:/Work/DEI/xmlsh/trunk/src" comment="This is a file"/>
  <file name="test" path="C:/Work/DEI/xmlsh/trunk/test" comment="This is a file"/>
  <file name="unix" path="C:/Work/DEI/xmlsh/trunk/unix" comment="This is a file"/>
  <file name="win32" path="C:/Work/DEI/xmlsh/trunk/win32" comment="This is a file"/>
  <file name="xmlsh.log" path="C:/Work/DEI/xmlsh/trunk/xmlsh.log" comment="This is a file"/>
</dir>



Implementation

The xaddattribute command is implemented as a built-in xsh script

xed -matches "$1" -a <[ attribute { $_2 }  { $_3 } ]>



Return Value

Returns 0 if the command executed successfully, 1 if there was an error.

Commands
xed
xdelete
CategoryCommands
CommandsPosix
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki