Created
August 6, 2020 15:24
-
-
Save jonathanduke/27f440de0ddb764b88194771be4564e8 to your computer and use it in GitHub Desktop.
This XSLT can be applied to a DriveImage XML file to create a batch file that will reapply the file attributes (hidden, system, read only, etc.) after extracting files from Browse mode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<!-- | |
Based on: https://gist.github.com/jonathanduke/27f440de0ddb764b88194771be4564e8#file-driveimagexmlattrib-xsl | |
Applies to: https://www.runtime.org/driveimage-xml.htm | |
Public domain: http://unlicense.org/ | |
Modify as you wish, but you are encouraged to leave this comment for future reference in case the original is updated. | |
--> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="text" /> | |
<xsl:template match="/"> | |
<xsl:apply-templates select="//filetree/f"> | |
<xsl:with-param name="Path"><xsl:value-of select="//driveletter[1]" /></xsl:with-param> | |
</xsl:apply-templates> | |
<xsl:apply-templates select="//filetree/d[translate(n,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ') != '$RECYCLE.BIN']"> | |
<xsl:with-param name="Path"><xsl:value-of select="//driveletter[1]" /></xsl:with-param> | |
</xsl:apply-templates> | |
</xsl:template> | |
<xsl:template match="d"> | |
<xsl:param name="Path" /> | |
<xsl:if test="at != '$00000010'">attrib<xsl:apply-templates select="at" /> "<xsl:value-of select="$Path" disable-output-escaping="yes" />\<xsl:value-of select="n" disable-output-escaping="yes" />" | |
</xsl:if> | |
<xsl:apply-templates select="f"> | |
<xsl:with-param name="Path"><xsl:value-of select="$Path" />\<xsl:value-of select="n" /></xsl:with-param> | |
</xsl:apply-templates> | |
<xsl:apply-templates select="d"> | |
<xsl:with-param name="Path"><xsl:value-of select="$Path" />\<xsl:value-of select="n" /></xsl:with-param> | |
</xsl:apply-templates> | |
</xsl:template> | |
<xsl:template match="f"> | |
<xsl:param name="Path" /> | |
<xsl:if test="at != '$00000020'">attrib<xsl:apply-templates select="at" /> "<xsl:value-of select="$Path" disable-output-escaping="yes" />\<xsl:value-of select="n" disable-output-escaping="yes" />" | |
</xsl:if> | |
</xsl:template> | |
<xsl:template match="at"> | |
<xsl:call-template name="num2attrs"> | |
<xsl:with-param name="num"> | |
<xsl:call-template name="hex2num"> | |
<xsl:with-param name="hex"> | |
<xsl:value-of select="translate(current(),'$','0')" /> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:with-param> | |
</xsl:call-template> | |
</xsl:template> | |
<xsl:template name="num2attrs"> | |
<xsl:param name="num" /> | |
<xsl:if test="floor($num div 1048576) mod 2"> +U</xsl:if> | |
<xsl:if test="floor($num div 524288) mod 2"> +P</xsl:if> | |
<xsl:if test="floor($num div 131072) mod 2"> +X</xsl:if> | |
<!--<xsl:if test="floor($num div 32768) mod 2"> +V</xsl:if>--> | |
<!--<xsl:if test="floor($num div 16384) mod 2"> +E</xsl:if>--> | |
<xsl:if test="floor($num div 8192) mod 2"> +I</xsl:if> | |
<xsl:if test="floor($num div 4096) mod 2"> +O</xsl:if> | |
<!--<xsl:if test="floor($num div 2048) mod 2"> +C</xsl:if>--> | |
<!--<xsl:if test="floor($num div 1024) mod 2"> +L</xsl:if>--> | |
<!--<xsl:if test="floor($num div 512) mod 2"> +F</xsl:if>--> | |
<!--<xsl:if test="floor($num div 256) mod 2"> +T</xsl:if>--> | |
<xsl:if test="floor($num div 128) mod 2"> -A</xsl:if> | |
<xsl:if test="floor($num div 32) mod 2"> +A</xsl:if> | |
<!--<xsl:if test="floor($num div 16) mod 2"> +D</xsl:if>--> | |
<xsl:if test="floor($num div 4) mod 2"> +S</xsl:if> | |
<xsl:if test="floor($num div 2) mod 2"> +H</xsl:if> | |
<xsl:if test="$num mod 2"> +R</xsl:if> | |
</xsl:template> | |
<xsl:template name="hex2num"> | |
<!--https://stackoverflow.com/a/22911132--> | |
<xsl:param name="hex"/> | |
<xsl:param name="num" select="0"/> | |
<xsl:param name="MSB" select="translate(substring($hex, 1, 1), 'abcdef', 'ABCDEF')"/> | |
<xsl:param name="value" select="string-length(substring-before('0123456789ABCDEF', $MSB))"/> | |
<xsl:param name="result" select="16 * $num + $value"/> | |
<xsl:choose> | |
<xsl:when test="string-length($hex) > 1"> | |
<xsl:call-template name="hex2num"> | |
<xsl:with-param name="hex" select="substring($hex, 2)"/> | |
<xsl:with-param name="num" select="$result"/> | |
</xsl:call-template> | |
</xsl:when> | |
<xsl:otherwise> | |
<xsl:value-of select="$result"/> | |
</xsl:otherwise> | |
</xsl:choose> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment