Difference between revisions of "Copy-All.xsl"

From TEIWiki
Jump to navigation Jump to search
m
m (just some whitespace changes)
Line 7: Line 7:
 
<pre><nowiki>
 
<pre><nowiki>
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+
<xsl:stylesheet version="1.0"
  version="1.0">
+
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
<!-- XSLT Template to copy anything, priority="-1" -->
+
  <!-- XSLT Template to copy anything, priority="-1" -->
<xsl:template match="@*|node()|text()|comment()|processing-instruction()" 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:copy>
</xsl:template>
+
      <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. -->
+
  <!-- If I were to do something different for an element here is how I'd do it. -->
<xsl:template match="fooBar">
+
  <xsl:template match="fooBar">
<barFoo><xsl:apply-templates/></barFoo>
+
    <barFoo><xsl:apply-templates/></barFoo>
</xsl:template>
+
  </xsl:template>
  
 
</xsl:stylesheet>
 
</xsl:stylesheet>
  
 
</nowiki></pre>
 
</nowiki></pre>

Revision as of 02:01, 2 July 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 version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- 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 were 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>