Created
March 17, 2024 05:45
-
-
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
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"?> | |
<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