Print

Print


Thank you, Jaime. I ended up finding a similar task on StackOverflow that I
was able to modify.

For others who may need it (getting EAD3 ready), I've pasted it below.
There may be a more elegant way to handle attributes, but I couldn't figure
it out. Perhaps someone else can. (Because of the way attributes are
handled, you may need to modify for your institution.)

Nathan

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"
        doctype-public="+//ISBN 1-931666-00-8//DTD ead.dtd (Encoded
Archival Description (EAD) Version 2002)//EN"
        doctype-system="ead.dtd" indent="yes"/>
    <xsl:template match="* | processing-instruction() | comment()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
    <xsl:key name="kNodeByPrecedingBlock"
match="unittitle/node()[not(self::unitdate)]"

use="generate-id((..|preceding-sibling::*[self::unitdate][1])[last()])"/>
    <xsl:template match="did">
        <did>
            <xsl:apply-templates select="node()|@*"/>
        </did>
    </xsl:template>
    <xsl:template match="unittitle">
        <xsl:apply-templates select=".|unitdate" mode="group"/>
    </xsl:template>
    <xsl:template match="unitdate">
        <xsl:variable name="normal" select="@normal"/>
        <xsl:variable name="type" select="@type"/>
        <xsl:variable name="label" select="@label"/>
        <xsl:variable name="analog" select="@encodinganalog"/>
        <unitdate>
            <xsl:if test="$label != ''">
                <xsl:attribute name="label">
                    <xsl:value-of select="$label"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$analog != ''">
                <xsl:attribute name="encodinganalog">
                    <xsl:value-of select="$analog"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:attribute name="era">ce</xsl:attribute>
            <xsl:attribute name="calendar">gregorian</xsl:attribute>
            <xsl:if test="$normal != ''">
                <xsl:attribute name="normal">
                    <xsl:value-of select="$normal"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:if test="$type != ''">
                <xsl:attribute name="type">
                    <xsl:value-of select="$type"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:apply-templates/>
        </unitdate>
    </xsl:template>
    <xsl:template match="unittitle" mode="group" name="makeUnittitle">
        <xsl:variable name="vGroup"
select="key('kNodeByPrecedingBlock',generate-id())"/>
        <xsl:variable name="label" select="@label"/>
        <xsl:variable name="analog" select="@encodinganalog"/>
        <xsl:if test="$vGroup">
            <unittitle>
                <xsl:if test="$label != ''">
                    <xsl:attribute name="label">
                        <xsl:value-of select="$label"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:if test="$analog != ''">
                    <xsl:attribute name="encodinganalog">
                        <xsl:value-of select="$analog"/>
                    </xsl:attribute>
                </xsl:if>
                <xsl:apply-templates select="$vGroup"/>
            </unittitle>
        </xsl:if>
    </xsl:template>
    <xsl:template match="*" mode="group">
        <xsl:apply-templates select="."/>
        <xsl:call-template name="makeUnittitle"/>
    </xsl:template>
    <xsl:template match="*/text()[normalize-space()]">
        <xsl:value-of select="normalize-space()"/>
    </xsl:template>
    <xsl:template match="*/text()[not(normalize-space())]"/>
</xsl:stylesheet>


On Fri, Nov 15, 2013 at 2:01 PM, Nathan Tallman <[log in to unmask]> wrote:

> Does anyone have a stylesheet that promotes unitdate to a sibling element,
> if it's a child element? If so, can you share it?
>
> Example
> orig - <unittitle>Correspondence, <unitdate>1984.</unitdate></unittitle>
>
> new -- <unittitle>Correspondence, </unittitle>
>           <unitdate>1984.</unitdate>
>
> Also need to remove the punctuation/whitespace, but I think I know how to
> handle that.
>
> Thanks!
> Nathan
>
>