Skip to content

Instantly share code, notes, and snippets.

@spikeheap
Last active November 9, 2015 10:48
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 spikeheap/695f79e52784cbe39d7f to your computer and use it in GitHub Desktop.
Save spikeheap/695f79e52784cbe39d7f to your computer and use it in GitHub Desktop.
Add `m` attribute to all leaf nodes
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"
xmlns:d="http://nihr.ac.uk/nhic/ICU/UCL/finalv8.3.2">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="dateNow" select="format-date(current-date(), '[Y0001]-[M01]-[D01]')"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[starts-with(name(), 'd:NIHR_HIC_ICU_')]">
<xsl:variable name="elementName" select="name()"/>
<xsl:element name="{$elementName}">
<xsl:attribute name="m">
<xsl:value-of select="$dateNow" />
</xsl:attribute>
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment