Skip to content

Instantly share code, notes, and snippets.

@jamescummings
Last active April 30, 2020 15:49
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 jamescummings/554ae1e8f215ce10c232518386aeafe5 to your computer and use it in GitHub Desktop.
Save jamescummings/554ae1e8f215ce10c232518386aeafe5 to your computer and use it in GitHub Desktop.
An example identity transform XSLT stylesheet
<?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"
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns="http://www.tei-c.org/ns/1.0"
xpath-default-namespace="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="xs tei"
version="2.0">
<!-- Notice TEI namespace is also given in 'xpath-default-namespace' -->
<!--
Basic Identity Transform Example
Date: 2020-04-30
By: James Cummings
License: CC+BY
-->
<!-- Indent output -->
<xsl:output indent="yes"/>
<!-- Copy all input to output except below -->
<xsl:template match="@*|node()" mode="#all">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<!-- Copy divs but add numbered @xml:id -->
<xsl:template match="body/div">
<xsl:variable name="num"><xsl:number count="div" level="any" from="body"/></xsl:variable>
<xsl:copy>
<xsl:attribute name="xml:id"><xsl:value-of select="concat('div', $num)"/></xsl:attribute>
<xsl:apply-templates select="@*[not(name()='xml:id')]|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment