View Single Post
Old 14th December 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,779
Default

You can generate those 'mv' commands with XSLT though.

Source XML file "files,xml":
Code:
<?xml version="1.0" ?>
<?xml-stylesheet href="rename.xsl" type="text/xsl" ?>

<collection>
    <file>latest-pkg</file>
    <file>latest-pkg-calyx</file>
    <file>latest-pkg-erlangen</file>
    <file>latest-pkg-esat</file>
    <file>latest-pkg-plig</file>
    <file>latest-pkg-stacken</file>
</collection>
The XSLT file "rename.xsl":
Code:
<?xml version="1.0" encoding='UTF-8' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 


<xsl:output
    method='html'
    omit-xml-declaration='no'
    indent='yes' 
    standalone='yes'
    doctype-public='-//W3C//DTD XHTML 1.0 Strict//EN'
    doctype-system='http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
/>


<xsl:template match="/collection">
  <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"  >
    <head>
      <title>
        Renaming a file with XSL
     </title>
    </head>
    <body>
        <xsl:call-template name='show_original' />
        <xsl:call-template name='show_rename_cmd' />
    </body>
  </html>
</xsl:template>


<xsl:template name="show_original">
  <h1>Original file names</h1>
    <ul>
      <xsl:for-each select='file' >
        <li><xsl:value-of select="." /> </li>
      </xsl:for-each>
    </ul>
</xsl:template>


<xsl:template name="show_rename_cmd">
  <h1>Rename command</h1>
      <ul>
  <xsl:for-each select='file' >
         <li>
            <xsl:value-of select='concat("mv ", current(), " ")' />
            <xsl:value-of select="substring-before( current(),'-')" />
            <xsl:text>_</xsl:text>
            <xsl:value-of select="substring-after( current(),'-')" />
         </li>
  </xsl:for-each>
      </ul>
</xsl:template>

</xsl:stylesheet>
Pointing a modern browser to "files.xml" will show the following:
Code:
Original file names

    * latest-pkg
    * latest-pkg-calyx
    * latest-pkg-erlangen
    * latest-pkg-esat
    * latest-pkg-plig
    * latest-pkg-stacken

Rename command

    * mv latest-pkg latest_pkg
    * mv latest-pkg-calyx latest_pkg-calyx
    * mv latest-pkg-erlangen latest_pkg-erlangen
    * mv latest-pkg-esat latest_pkg-esat
    * mv latest-pkg-plig latest_pkg-plig
    * mv latest-pkg-stacken latest_pkg-stacken
If you don't believe me, point your browser at files.xml
Feel free to view the source code. In firefox: View -> Page Source, or just press CNTRL+U
Attached Files
File Type: tgz renaming.tgz (812 Bytes, 56 views)
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump

Last edited by J65nko; 14th December 2008 at 06:37 PM. Reason: Added download
Reply With Quote