GenerateDefaultAttributeRemover.xslt

If you want to remove default attributes from your TEI P4 XML files, this may be for you. If you just use vanilla TEI Lite P4, then you could just use Remove-Default-Attributes.xslt.

This method is more compliated, but works for any TEI P4 DTD, and probably for lots of non-TEI DTDs as well.

 
 * 1) If you don't have one already, generate a flat version of your DTD with the pizza chef.
 * 2) Convert the flat DTD to RELAX NG (XML syntax). This may be done using trang; oXygen gives a nice GUI front-end to trang from the "Tools" menu (it's called "Trang converter…".)
 * 3) Resolve references to attribute lists in the resulting RELAX NG schema by applying relaxng_refAtt_resolver.xslt.
 * 4) Feed the resulting schema as input to this stylesheet. The output will be a stylesheet that will remove default attributes from instances.



  1.0 &#x0A;  This stylesheet generated by generate_default_attr_remover.xslt  &#x0A;</xsl:text>  Generic copy-everything template </xsl:comment> <xsl:element name="xsl:template"> <xsl:attribute name="match">*|@*|processing-instruction|comment</xsl:attribute> <xsl:element name="xsl:copy"> <xsl:element name="xsl:apply-templates"> <xsl:attribute name="select" >*|@*|text|processing-instruction|comment</xsl:attribute> </xsl:element> </xsl:element> </xsl:element>

&#x0A;</xsl:text>  get rid of TEIform= attrs whose value match GI </xsl:comment>  see http://www.tei-c.org/wiki/index.php/Remove-Default-Attributes.xslt </xsl:comment>  for detailed comments. </xsl:comment>

<xsl:element name="xsl:template"> <xsl:attribute name="match">@TEIform</xsl:attribute> <xsl:element name="xsl:if"> <xsl:attribute name="test">not( . = name(..) )</xsl:attribute> <xsl:element name="xsl:attribute"> <xsl:attribute name="name">TEIform</xsl:attribute> <xsl:element name="xsl:value-of"> <xsl:attribute name="select">.</xsl:attribute> </xsl:element> </xsl:element> </xsl:element> </xsl:element>

&#x0A;</xsl:text>  When we hit an element/attribute combination that has a default value </xsl:comment>  in the schema, test to see if the value specified is the same as the </xsl:comment>  default value in the schema. If it is not, write out the attribute as </xsl:comment>  it was specified in the instance; if it is, do nothing, thus dropping </xsl:comment>  the entire attribute from the output. </xsl:comment> &#x0A;</xsl:text> <xsl:apply-templates select="//rng:attribute[@a:defaultValue]"/>

</xsl:element> </xsl:template>

<xsl:template match="rng:attribute[@a:defaultValue]"> <xsl:if test="not(@name='TEIform')"> &#x0A;</xsl:text> <xsl:element name="xsl:template"> <xsl:attribute name="match"> <xsl:value-of select="ancestor::rng:element[1]/@name"/> /@</xsl:text> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:element name="xsl:if"> <xsl:attribute name="test"> not( . = '</xsl:text>           <xsl:value-of select="@a:defaultValue"/>            ' )</xsl:text> </xsl:attribute> <xsl:element name="xsl:attribute"> <xsl:attribute name="name"> <xsl:value-of select="@name"/> </xsl:attribute> <xsl:element name="xsl:value-of"> <xsl:attribute name="select">.</xsl:attribute> </xsl:element> </xsl:element> </xsl:element> </xsl:element> </xsl:if> </xsl:template>

</xsl:stylesheet>