Difference between revisions of "Copy-All.xsl"

From TEIWiki
Jump to navigation Jump to search
m (just some whitespace changes)
m (More intro)
Line 1: Line 1:
 
[[Category:P4toP5]]
 
[[Category:P4toP5]]
 
[[Category:XSLT]]
 
[[Category:XSLT]]
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 elementsThe fictional element '''fooBar''' is used as an example of how one would do that.
+
== 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:
 +
  <nowiki><xsl:import href="Copy-All.xsl"/></nowiki>
 +
at the beginning of your XSLT(See the [[Category:P4toP5 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 ==
 
<pre><nowiki>
 
<pre><nowiki>
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>

Revision as of 15:01, 4 July 2006


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:

 <xsl:import href="Copy-All.xsl"/>

at the beginning of your XSLT. (See the 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

<?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>