Skip to content

Instantly share code, notes, and snippets.

@ori229
Created March 17, 2024 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ori229/a07ff60f58cd710df48870e713d380e7 to your computer and use it in GitHub Desktop.
Save ori229/a07ff60f58cd710df48870e713d380e7 to your computer and use it in GitHub Desktop.
XSL that retrieves all fields in an XML, and shows the full path of the field and its data
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<style>
table, th, td {
border: 1px solid black; border-collapse: collapse; width:100%;
}
th, td {
padding: 5px; max-width:200px; word-wrap: break-word;
}
</style>
</head>
<body>
<table>
<tr>
<th>Path</th>
<th>Value</th>
</tr>
<xsl:apply-templates select="//*[not(*)]"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="*">
<tr>
<td>
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
<xsl:if test="position() != last()">
<xsl:text>/</xsl:text>
</xsl:if>
</xsl:for-each>
</td>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment