Difference between revisions of "Copy-All.xsl"

From TEIWiki
Jump to navigation Jump to search
m
m
Line 6: Line 6:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
<?xml version="1.0"?>
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
   version="1.0">
 
   version="1.0">

Revision as of 16:05, 21 June 2006

This is a utility XSLT script. It should be placed in the same directory as PipedStylesheets.bash and the other XSLT stylesheets you want to use. (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.

You can use this stylesheet as well to copy the entire contents of an XML document *except* do something to some particular elements. The fictional element fooBar is used as an example of how one would do that.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

<!-- XSLT Template to copy anything, priority="-1" -->
<xsl:template match="@*|node()|text()|comment()|processing-instruction()" priority="-1">
 <xsl:copy><xsl:apply-templates select="@*|node()|text()|comment()|processing-instruction()"/></xsl:copy>
</xsl:template>

<!-- If I was to do something different for an element here is how I'd do it. -->
<xsl:template match="fooBar">
<barFoo><xsl:apply-templates/></barFoo>
</xsl:template>

</xsl:stylesheet>