Difference between revisions of "Id-to-xml-id.xslt"
Jump to navigation
Jump to search
(initial check-in with no commentary) |
Stuartyeates (talk | contribs) |
||
| (10 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| + | This stylesheet changes id= attributes to xml:id= attributes, except | ||
| + | when on <language>, in which case they become ident= attributes. | ||
| + | That is all. | ||
<pre><nowiki><?xml version="1.0" encoding="UTF-8"?> | <pre><nowiki><?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Tiny XSLT 1.0 stylesheet that reads in a TEI P4:2004 file (or --> | <!-- Tiny XSLT 1.0 stylesheet that reads in a TEI P4:2004 file (or --> | ||
<!-- any other XML file, really) and writes out the same file with --> | <!-- any other XML file, really) and writes out the same file with --> | ||
| − | <!-- the id= attribute changed to the xml:id= attribute. --> | + | <!-- the id= attribute changed to the xml:id= attribute, except --> |
| − | + | <!-- for id= of <language>, which becomes ident=. --> | |
| + | |||
<!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium --> | <!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium --> | ||
| Line 12: | Line 16: | ||
<!-- issue a warning). --> | <!-- issue a warning). --> | ||
| − | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | + | <!-- Written 2006-05-05 by Syd Bauman --> |
| − | xmlns:tei="http://www.tei-c.org/ns/1.0" | + | <!-- updated 2008-05-02 by Syd Bauman: use ident=, not xml:id=, for <language> --> |
| − | + | ||
| + | <xsl:stylesheet version="1.0" | ||
| + | xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
| + | xmlns:tei="http://www.tei-c.org/ns/1.0"> | ||
| + | |||
| + | <xsl:import href="Copy-All.xsl"/> | ||
<xsl:output method="xml" | <xsl:output method="xml" | ||
| Line 20: | Line 29: | ||
cdata-section-elements="eg"/> | cdata-section-elements="eg"/> | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
<!-- special template for elements with id= that have to change --> | <!-- special template for elements with id= that have to change --> | ||
| Line 33: | Line 36: | ||
</xsl:if> | </xsl:if> | ||
<xsl:element name="{name(.)}"> | <xsl:element name="{name(.)}"> | ||
| − | <xsl: | + | <xsl:variable name="newIDattr"> |
| − | <!-- For the value of the new xml:id= attribute use id= | + | <xsl:choose> |
| + | <xsl:when test="name(.)='language'"> | ||
| + | <xsl:text>ident</xsl:text> | ||
| + | </xsl:when> | ||
| + | <xsl:otherwise> | ||
| + | <xsl:text>xml:id</xsl:text> | ||
| + | </xsl:otherwise> | ||
| + | </xsl:choose> | ||
| + | </xsl:variable> | ||
| + | <xsl:attribute name="{$newIDattr}"> | ||
| + | <!-- For the value of the new xml:id= or ident= attribute, use --> | ||
| + | <!-- the value of the current input id= --> | ||
<xsl:value-of select="@id"/> | <xsl:value-of select="@id"/> | ||
</xsl:attribute> | </xsl:attribute> | ||
| Line 44: | Line 58: | ||
</xsl:template> | </xsl:template> | ||
| − | </xsl:stylesheet> | + | </xsl:stylesheet></nowiki></pre> |
| − | </ | + | [[Category:P4toP5]] |
| − | + | [[Category:XSLT]] | |
| − | [[Category: | + | [[User:Syd|Syd]] 06:52, 26 May 2006 (BST) |
Latest revision as of 08:15, 14 March 2010
This stylesheet changes id= attributes to xml:id= attributes, except when on <language>, in which case they become ident= attributes. That is all.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Tiny XSLT 1.0 stylesheet that reads in a TEI P4:2004 file (or -->
<!-- any other XML file, really) and writes out the same file with -->
<!-- the id= attribute changed to the xml:id= attribute, except -->
<!-- for id= of <language>, which becomes ident=. -->
<!-- Copyleft 2006 Syd Bauman and the Text Encoding Initiative Consortium -->
<!-- The output of this stylesheet is not P5-comnpliant XML; it is just -->
<!-- the same P4 document with xml:id= instead of id=. -->
<!-- Note that if an element already has both an id= and an xml:id=, we -->
<!-- nuke the old xml:id= and replace it with what used to be id= (and -->
<!-- issue a warning). -->
<!-- Written 2006-05-05 by Syd Bauman -->
<!-- updated 2008-05-02 by Syd Bauman: use ident=, not xml:id=, for <language> -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tei="http://www.tei-c.org/ns/1.0">
<xsl:import href="Copy-All.xsl"/>
<xsl:output method="xml"
encoding="UTF-8"
cdata-section-elements="eg"/>
<!-- special template for elements with id= that have to change -->
<xsl:template match="*[@id]">
<xsl:if test="@xml:id">
<xsl:message>WARNING: deleting the existing xml:id=<xsl:value-of select="@xml:id"/> attribute of <<xsl:value-of select="name(.)"/> id=<xsl:value-of select="@id"/>>.</xsl:message>
</xsl:if>
<xsl:element name="{name(.)}">
<xsl:variable name="newIDattr">
<xsl:choose>
<xsl:when test="name(.)='language'">
<xsl:text>ident</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>xml:id</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="{$newIDattr}">
<!-- For the value of the new xml:id= or ident= attribute, use -->
<!-- the value of the current input id= -->
<xsl:value-of select="@id"/>
</xsl:attribute>
<!-- Now copy over all other attributes (i.e., all but id= and xml:id=) -->
<xsl:copy-of select="attribute::*[not(name()='id') and not(name()='xml:id')]"/>
<!-- Now copy over all the content -->
<xsl:apply-templates select="./*|./text()|./processing-instruction()|./comment()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Syd 06:52, 26 May 2006 (BST)