Created
January 23, 2025 23:39
-
-
Save TiloGit/3c2d49d09696c7054d3f76c78c341b1b to your computer and use it in GitHub Desktop.
Revisions
-
TiloGit created this gist
Jan 23, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ ### 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")) } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ <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>