Remove-Default-Attributes.xslt

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
 <!DOCTYPE EtfDocumentaryCreditNotification SYSTEM "EtfDocumentaryCreditNotification466_1_0.dtd">         CHAETFData_1               0001         0000                     0002         0001                  XML      GTF            SB01</isaccID>      <traceLevel/>      <originalSendTime/>      <patternType>DSY</patternType>      <errorCode/>           <errorText/>      <completionCode/>      <reasonCode/>      <mqObject/>      <flowNode/>   </BaseHeader>   <AppHeader>      <eventDomain>CHA</eventDomain>      <eventCategory>ONL</eventCategory>      <businessUnit>0009</businessUnit>      <businessDay>ref01</businessDay>      <eventTimestamp>2002-04-18-09.28.04.287551</eventTimestamp>   </AppHeader>   <EtfHeader>      <cifNumber>083503619132</cifNumber>      ZRH      <orgUnit>SGAT 115</orgUnit>      <dossierNumber>SGAT 115-054146</dossierNumber>      <refNumber>SGAT 115-054146</refNumber>      <eventId>ISS</eventId>      <eventSeqNumber>0</eventSeqNumber>      <msgSeqNumber>1</msgSeqNumber>      01      2006-03-17 11:45:28      <entityId>001</entityId>      B      <numberOfElements>0</numberOfElements>      <ProcessInformationCustomer>         SGAT-115-054146_2006-03-17_466              </ProcessInformationCustomer>   </EtfHeader>   <DocumentaryCreditNotification xmlns:dt=" http://www.bolero.net/io/xmlns/datatype/1.0">      <Header xmlns:cmp=" http://www.bolero.net/io/xmlns/header/1.0">         <cmp:DocumentID>            <cmp:RID>CREDIT-SUISSE-USERTEST.IMAP</cmp:RID>            <cmp:GeneralID>SGAT-115-054146A0</cmp:GeneralID>            <cmp:Version>V1.0</cmp:Version>         </cmp:DocumentID>         <cmp:DocType>            <cmp:DocTypeCode>466</cmp:DocTypeCode>         </cmp:DocType>         <cmp:Status>Final</cmp:Status>      </Header>      <Body>         <Party>            <partyType>APP</partyType>            <partyName>Glencore International AG</partyName>            <PartyId>               <partyIdType>INT</partyIdType>               <partyIdValue>083503619132</partyIdValue>            </PartyId>            <PartyAddress>               Glencore International AG               Baarermattstrasse 3               Postfach 777               6341 Baar            </PartyAddress>            <Contact>               <contactType>TEL</contactType>               <contactValue>(41)41-7092947</contactValue>            </Contact>            <Contact>               <contactType>FAX</contactType>               <contactValue>(41)41-7093000</contactValue>            </Contact>         </Party>         <Party>            <partyType>ADB</partyType>            <partyName>Bangkok Bank Public Company</partyName>            <PartyId>               <partyIdType>INT</partyIdType>               <partyIdValue>083509920500</partyIdValue>            </PartyId>            <PartyAddress>               Bangkok Bank Public Company               Limited               333 Silom Road               TH-Bangkok 10500            </PartyAddress>         </Party>         <Party>            <partyType>BEN</partyType>            <partyName>Eximp</partyName>            <PartyId>               <partyIdType>INT</partyIdType>               <partyIdValue/>            </PartyId>            <PartyAddress>               Eximp               Mainstreet               London            </PartyAddress>         </Party>         <Party>            <partyType>ISB</partyType>            <partyName>Credit Suisse</partyName>            <PartyId>               <partyIdType>INT</partyIdType>               <partyIdValue>083510483505</partyIdValue>            </PartyId>            <PartyAddress>               Credit Suisse               Hauptsitz               8070 Zuerich            </PartyAddress>         </Party>         <Date>            <dateType>EXP</dateType>            <dateValue>2006-06-30</dateValue>         </Date>         <Date>            <dateType>ISS</dateType>            <dateValue>2006-03-17</dateValue>         </Date>         <Reference>            <referenceType>999</referenceType>            <referenceValue>RS170306T50</referenceValue>            <ReferenceSource>               <partyType>APP</partyType>            </ReferenceSource>         </Reference>         <Reference>            <referenceType>466</referenceType>            <referenceValue>SGAT 115-054146</referenceValue>            <ReferenceSource>               <partyType>ISB</partyType>            </ReferenceSource>         </Reference>         <Location>            <locationType>SHF</locationType>            <LocationId>               <locationName>Mombasa</locationName>            </LocationId>         </Location>         <Location>            <locationType>SHT</locationType>            <LocationId>               <locationName>Basel</locationName>            </LocationId>         </Location>         <Location>            <locationType>DEL</locationType>            <LocationId>               <locationName>Basel</locationName>            </LocationId>         </Location>         <DocumentaryCreditNotificationParticulars>            <documentaryCreditType>IRREVOCABLE</documentaryCreditType>            <documentaryCreditSubType>NOR</documentaryCreditSubType>            <DocumentaryCreditAmount>               3000.00               <currencyCode>CHF</currencyCode>            </DocumentaryCreditAmount>            <DocumentaryCreditAmountVariance>               <documentaryCreditAmountVarianceType>NOT EXCEEDING</documentaryCreditAmountVarianceType>               <PercentageVariance/>            </DocumentaryCreditAmountVariance>            <DocumentaryCreditAvailability>               <DocumentaryCreditAvailableWith>                  <documentaryCreditAvailabilityParty>ISB</documentaryCreditAvailabilityParty>               </DocumentaryCreditAvailableWith>               <documentaryCreditAvailabilityType>BY PAYMENT</documentaryCreditAvailabilityType>            </DocumentaryCreditAvailability>            <DocumentaryCreditValidity>               <documentaryCreditValidityParty>ISB</documentaryCreditValidityParty>            </DocumentaryCreditValidity>            <confirmationInstructionType>WITHOUT</confirmationInstructionType>            <PresentationPeriod>               2 weeks            </PresentationPeriod>            <ShipmentPeriod>               One week            </ShipmentPeriod>            <PartialShipment>               <partialShipmentIndicator>FALSE</partialShipmentIndicator>            </PartialShipment>            <Transhipment>               <transhipmentIndicator>FALSE</transhipmentIndicator>            </Transhipment>            <Incoterms>               <incotermsCode>CIF</incotermsCode>            </Incoterms>            <documentIssueType>SWT</documentIssueType>            <amendmentAdviceRefusalIndicator>FALSE</amendmentAdviceRefusalIndicator>         </DocumentaryCreditNotificationParticulars>         <Goods>            <GoodsDescription>               coffee            </GoodsDescription>         </Goods>         <Documentation>            Invoice         </Documentation>      </Body>   </DocumentaryCreditNotification> </EtfDocumentaryCreditNotification>

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
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:tei="http://www.tei-c.org/ns/1.0"> <xsl:output indent="yes" method="xml" omit-xml-declaration="no" cdata-section-elements="eg"/> <xsl:template match="*|@*|processing-instruction|comment"> <xsl:copy> <xsl:apply-templates select="*|@*|text|processing-instruction|comment"/> </xsl:copy> </xsl:template> <xsl:template match="@TEIform"> <xsl:if test="not( . = name(..) )"> <xsl:attribute name="TEIform"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template>

<xsl:template match="gi/@TEI"> <xsl:if test="not( . = 'yes' )"> <xsl:attribute name="TEI"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="note/@anchored"> <xsl:if test="not( . = 'yes' )"> <xsl:attribute name="anchored"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="cell/@cols"> <xsl:if test="not( . = '1' )"> <xsl:attribute name="cols"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="textClass/@default | bibl/@default | biblFull/@default | editorialDecl/@default | langUsage/@default | listBibl/@default | projectDesc/@default | samplingDecl/@default | sourceDesc/@default"> <xsl:if test="not( . = 'NO' )"> <xsl:attribute name="default"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="q/@direct"> <xsl:if test="not( . = 'unspecified' )"> <xsl:attribute name="direct"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="refsDecl/@doctype"> <xsl:if test="not( . = 'TEI.2' )"> <xsl:attribute name="doctype"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="xref/@from | xptr/@from"> <xsl:if test="not( . = 'ROOT' )"> <xsl:attribute name="from"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="lg/@org | div0/@org | div1/@org | div2/@org | div3/@org | div4/@org | div5/@org | div6/@org | div7/@org | div/@org"> <xsl:if test="not( . = 'uniform' )"> <xsl:attribute name="org"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="seg/@part | ab/@part | div0/@part | div1/@part | div2/@part | div3/@part | div4/@part | div5/@part | div6/@part | div7/@part | div/@part | l/@part | lg/@part | s/@part"> <xsl:if test="not( . = 'N' )"> <xsl:attribute name="part"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="note/@place"> <xsl:if test="not( . = 'unspecified' )"> <xsl:attribute name="place"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="editor/@role"> <xsl:if test="not( . = 'editor' )"> <xsl:attribute name="role"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="cell/@role | row/@role"> <xsl:if test="not( . = 'data' )"> <xsl:attribute name="role"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="cell/@rows"> <xsl:if test="not( . = '1' )"> <xsl:attribute name="rows"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="lg/@sample | div0/@sample | div1/@sample | div2/@sample | div3/@sample | div4/@sample | div5/@sample | div6/@sample | div7/@sample | div/@sample"> <xsl:if test="not( . = 'complete' )"> <xsl:attribute name="sample"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="del/@statuss"> <xsl:if test="not( . = 'unremarkable' )"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="availability/@status"> <xsl:if test="not( . = 'unknown' )"> <xsl:attribute name="status"> <xsl:value-of select="."/> </xsl:attribute> </xsl:if> </xsl:template> <xsl:template match="teiHeader/@status"> <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>