Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Created January 23, 2025 23:39
Show Gist options
  • Save TiloGit/3c2d49d09696c7054d3f76c78c341b1b to your computer and use it in GitHub Desktop.
Save TiloGit/3c2d49d09696c7054d3f76c78c341b1b to your computer and use it in GitHub Desktop.
Convert IBM FileNet GCD XML file to readable and compareable html
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="/">
<html>
<body>
<h2 style="text-align:center">============================ GCD xml info ============================</h2>
<h2 style="text-align:center">GCD epoch ID: <xsl:value-of select="/version/@epoch"/></h2>
<table align="center" border="1" width="1100">
<tr bgcolor="#9acd32">
<th style="text-align:left">Name</th>
<th style="text-align:left">Value dump</th>
<th style="text-align:left">Name dump</th>
</tr>
<xsl:for-each select="/version/object/attribute">
<tr>
<td><xsl:value-of select="@name"/></td>
<td> <xsl:for-each select="value/@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
<td> <xsl:for-each select="@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
</tr>
</xsl:for-each>
</table>
<h2 style="text-align:center">============== Top level object info loop ==============</h2>
<xsl:for-each select="/version/object/object">
<h2 style="text-align:center"><xsl:value-of select="@ObjectTypeName"/></h2>
<table align="center" border="1" width="1100">
<tr bgcolor="#f7acb7">
<th style="text-align:left">Name</th>
<th style="text-align:left">Value dump</th>
<th style="text-align:left">Name dump</th>
</tr>
<xsl:for-each select="attribute">
<tr>
<td><xsl:value-of select="@name"/></td>
<td> <xsl:for-each select="value/@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
<td> <xsl:for-each select="@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
</tr>
</xsl:for-each>
</table>
<h2 style="text-align:center">============== Sub Object info loop ==============</h2>
<xsl:for-each select="object">
<h2 style="text-align:center"><xsl:value-of select="@ObjectTypeName"/></h2>
<table align="center" border="1" width="1100">
<tr bgcolor="#79ccf6">
<th style="text-align:left">Name</th>
<th style="text-align:left">Value dump</th>
<th style="text-align:left">Name dump</th>
</tr>
<xsl:for-each select="attribute">
<tr>
<td><xsl:value-of select="@name"/></td>
<td> <xsl:for-each select="value/@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
<td> <xsl:for-each select="@*">
<xsl:value-of select="concat(name(), ': ', ., ' ')"/>
</xsl:for-each></td>
</tr>
</xsl:for-each>
</table>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
### Call like this.
### .\XMLconvert.ps1 <<Folder with XML to convert>> <<your-template.xsl>> << output folder >>
### .\XMLconvert.ps1 C:\temp\test-pretty-print C:\temp\test-pretty-print\gcd-prettyprint-template.xsl C:\temp\test-pretty-print\out
param ($xml, $xsl, $output)
if (-not $xml -or -not $xsl -or -not $output)
{
Write-Host "& .\xslt.ps1 [-xml-folder] xml-input-folder [-xsl] xsl-input [-output-folder] transform-output-folder"
exit;
}
trap [Exception]
{
Write-Host $_.Exception;
}
$ListofXML = Get-ChildItem $xml -File -filter *.xml
foreach ($xmlFile in $ListofXML) {
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load($xsl);
$outputFile = join-path $output ($($xmlFile.BaseName) + ".html")
[Void][System.IO.Directory]::CreateDirectory($output)
$xslt.Transform($xmlFile.Fullname, $outputFile);
Write-Host "generated output" $outputFile;
Write-Host "clean-up" $outputFile;
$string = get-content $outputFile
$cleanout = $string -replace "blob:(.*)","blob:--removed--"
#write-output $cleanout
$cleanout | Set-Content -Path $(join-path $output ($($xmlFile.BaseName) + "-clean.html"))
}
@TiloGit
Copy link
Author

TiloGit commented Jan 23, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment