Skip to content

Instantly share code, notes, and snippets.

View Ams627's full-sized avatar

Adrian Sims Ams627

  • Barclays
  • Prague, Czech Republic
View GitHub Profile
@Ams627
Ams627 / clip.txt
Created September 11, 2025 14:36
Public gist from clipboard
exclude-result-prefixes="msxsl exsl other"
@Ams627
Ams627 / clip.txt
Created September 11, 2025 14:35
Public gist from clipboard
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
@Ams627
Ams627 / clip.txt
Created September 11, 2025 13:25
Public gist from clipboard
# msxml_xslt.py
import sys, os
def main(argv):
if len(argv) < 3:
print("Usage: python msxml_xslt.py <input.xml> <stylesheet.xsl> [output.xml]", file=sys.stderr)
sys.exit(2)
in_arg, xsl_arg = argv[1], argv[2]
out_arg = argv[3] if len(argv) >= 4 else "output.xml"
@Ams627
Ams627 / clip.txt
Created September 11, 2025 12:45
Public gist from clipboard
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:msxsl"
exclude-result-prefixes="msxsl">
<!-- Example of turning an RTF into nodes -->
<xsl:variable name="frag">
<items><item a="1"/><item a="2"/></items>
</xsl:variable>
@Ams627
Ams627 / clip.txt
Created September 11, 2025 12:45
Public gist from clipboard
import win32com.client as win32
# Load XML
xml = win32.Dispatch("Msxml2.DOMDocument.6.0")
xml.async = False
xml.resolveExternals = False
xml.validateOnParse = False
if not xml.load(r"input.xml"):
raise RuntimeError(xml.parseError.reason)
@Ams627
Ams627 / clip.txt
Created September 11, 2025 10:59
Public gist from clipboard
txt = open("style_msxsl.xsl","r",encoding="utf-8").read()
txt = txt.replace("msxsl:node-set(", "exsl:node-set(")
if 'xmlns:exsl="http://exslt.org/common"' not in txt:
txt = txt.replace('<xsl:stylesheet',
'<xsl:stylesheet xmlns:exsl="http://exslt.org/common"')
xslt = etree.XSLT(etree.XML(txt.encode("utf-8")))
@Ams627
Ams627 / clip.txt
Created September 11, 2025 10:00
Public gist from clipboard
<xsl:template match="/">
<!-- collect once, reuse -->
<xsl:variable name="nodes" select="//Constituents/Constituent"/>
<xsl:if test="$nodes">
<Root>
<!-- either iterate... -->
<xsl:for-each select="$nodes">
<!-- do your per-Constituent work here, or call a template -->
<xsl:call-template name="emit-constituent"/>
</xsl:for-each>
@Ams627
Ams627 / clip.txt
Created September 11, 2025 09:46
Public gist from clipboard
<xsl:if test="Constituents/Constituent">
<!-- exists under the current node -->
</xsl:if>
@Ams627
Ams627 / clip.txt
Created September 11, 2025 09:28
Public gist from clipboard
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<!-- =======================
1) Data tables in vars
@Ams627
Ams627 / clip.txt
Created September 11, 2025 08:19
Public gist from clipboard
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<!-- =======================
1) Data tables in vars