Copy-All.xsl

Introduction
This is a utility XSLT script which copies the entire contents of an XML document to the output, except those elements specifically matched. One manner in which to use it is to include the statement:  at the beginning of your XSLT. (See the P4toP5 stylesheets which do this as an example.)

Use with "PipedStylesheets.bash" and "P4 enroute to P5.bash"
If using either of these bash scripts to pipeline a number of XSLT transformations, this stylesheet should be placed in the same directory as the script and the other stylesheets. (They import this one.) However, in naming this stylesheet make sure to call it 'Copy-All.xsl'. Specifically, make sure you have it capitalised, and that it ends '.xsl' not '.xslt' as the other stylesheets.

General Purpose Use
You can use this stylesheet as the basis of one to copy the entire contents of any XML document *except* do something to some particular elements. The fictional element fooBar is used as an example of how one would do something different to a particular element. However, if you are going to write several stylesheets, each using this functionality, then importing it in as above probably a better idea.

Stylesheet
 

    

  



P5 namespace version
If you are processing a TEI P5 document, whose elements will therefore be in the TEI namespace, and if you have an XSLT 2.0 processor, the following variant of the stylesheet makes your life easier by defining the xpath-default-namespace attribute on the stylesheet so that you can omit the tei:</tt> prefix in your XPath expressions: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="http://www.tei-c.org/ns/1.0">

<xsl:template match="@*|node|text|comment|processing-instruction" priority="-1">  <xsl:apply-templates select="@*|node|text|comment|processing-instruction"/> </xsl:copy> </xsl:template>

<xsl:template match="fooBar"> <xsl:apply-templates/></barFoo> </xsl:template>

</xsl:stylesheet>