Skip to content

Instantly share code, notes, and snippets.

@wjn
Created December 19, 2013 03:28
Show Gist options
  • Save wjn/8033990 to your computer and use it in GitHub Desktop.
Save wjn/8033990 to your computer and use it in GitHub Desktop.
Write Path: a utility that I use for XSLT debugging, which will show the present XPath location in an XML document.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="write-path">
<xsl:param name="path"/>
<xsl:param name="output"/>
<xsl:choose>
<xsl:when test="$path/parent::node()">
<xsl:call-template name="write-path">
<xsl:with-param name="output">
<xsl:choose>
<xsl:when test="$output">
<xsl:value-of select="concat(local-name($path), '/', $output)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name($path)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
<xsl:with-param name="path" select="$path/parent::node()"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('/',$output)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment