Useful little xsl tidbit

While avoiding my presentation, I discovered this useful xsl trick for copying an entire xml document and its attributes and changing only selected elements.

<xsl:template match="@*|node()">
   <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

We are working on migrating our finding aids out of Dyna Web and into eXist, this is including a transformation from SGML to XML and quite a bit of clean up. Chris (the Curator of Manuscripts) has been doing most of the work, but every once in a while we need to tweak the stylesheet, or create a new one, to deal with some special UVM eccentricity. In this case we had a c02 that contained a scopecontent element with a series of nested lists that we wanted to turn into <c03 level=”item”> elements.
The above code copies all the attributes and elements as is unless I have a special template for that element, then it follows the template’s rules. So then I added a convoluted template that creates the new c03 elements from the list items. The transformation is fairly quick even on large EAD files.

Advertisements

2 Responses to “Useful little xsl tidbit”

  1. Jon Gorman Says:

    This technique is known as the Identity Transform and those who want to see more examples can probably find them by searching using that phrase.

  2. wsalesky Says:

    Thanks Jon, that is helpful to know.

Comments are closed.


%d bloggers like this: