Remove-Default-Attributes.xslt

rolsit

Summary
This is a straightforward XSLT stylesheet for removing the default attributes from a TEI document. These are often provided by the DTD or schema, and can clutter up viewing of them.

Add any comments to the 'discussion' tab.

Required Input
While this may work on other documents it assumes a TEI Lite P4 XML document.

Expected Output
Same document, but with default attributes removed if they have the default values.

Known Restrictions or Problems
It only works on TEI P4 documents, and is not namespace-aware, but seems to work fine on these.

Stylesheet


             

 <xsl:if test="not( . = 'yes' )"> <xsl:attribute name="TEI"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'yes' )"> <xsl:attribute name="anchored"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = '1' )"> <xsl:attribute name="cols"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'NO' )"> <xsl:attribute name="default"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'unspecified' )"> <xsl:attribute name="direct"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'TEI.2' )"> <xsl:attribute name="doctype"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'ROOT' )"> <xsl:attribute name="from"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'uniform' )"> <xsl:attribute name="org"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'N' )"> <xsl:attribute name="part"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'unspecified' )"> <xsl:attribute name="place"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'editor' )"> <xsl:attribute name="role"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'data' )"> <xsl:attribute name="role"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = '1' )"> <xsl:attribute name="rows"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'complete' )"> <xsl:attribute name="sample"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'unremarkable' )"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'unknown' )"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>  <xsl:if test="not( . = 'new' )"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="xref/@targOrder | ptr/@targOrder | ref/@targOrder | xptr/@targOrder"> <xsl:if test="not( . = 'U' )"> <xsl:attribute name="targOrder"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="xref/@to | xptr/@to"> <xsl:if test="not( . = 'DITTO' )"> <xsl:attribute name="to"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="titlePart/@type"> <xsl:if test="not( . = 'main' )"> <xsl:attribute name="type"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="list/@type"> <xsl:if test="not( . = 'simple' )"> <xsl:attribute name="type"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="teiHeader/@type"> <xsl:if test="not( . = 'text' )"> <xsl:attribute name="type"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> </xsl:stylesheet>