Print

Print


Hi Marsha,

I think that you'd want your style sheet to look something like the following instead:

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="rootElement">
        <xsl:element name="{name()}">
        <xsl:apply-templates select="TitleWork">
            <xsl:sort select="roles/Name-Role[1]/party[1]/@xl:title"/>
        </xsl:apply-templates>
        </xsl:element>
    </xsl:template>

At the point that you're attempting your sort, you've already matched  the template for the TitleWork, so it doesn't have anything to sort on (at least, that's my first hunch).  Here, however, it's catching on the "rootElement" element that you listed in your XML example, and when it's applying the template for TitleWork, it's sorting on the specific attribute that you listed.  Does that work?


Mark




From: Encoded Archival Description List [mailto:[log in to unmask]] On Behalf Of Marsha Maguire
Sent: Friday, August 24, 2012 1:44 PM
To: [log in to unmask]
Subject: Thank you! And of course, another XSLT question

Greetings to the list,

And thanks to a number of you who answered my questions about getting started with XSLT stylesheets, both on the list and through email. Thanks especially to John Bewley, whose MARC-to-EAD stylesheet I was able to customize and use to convert MARC records for sound recordings into EAD <c02>-level descriptions, and to Mike Ferrando for offering help on the final product. And to Mark Carlson, who basically wrote a stylesheet I used to convert records exported from a local collections management database into component-level EAD descriptions -- and also walked me through how it worked. Thank-you to Michael Fox and Michele Combs for always offering their expertise; aren't archivists the best?

This is starting to sound like an awards show.  :-)  But I really do appreciate everyone's help. I've encountered a problem I can't solve, though (I've tried many different approaches with no success), so I have another question. When I export an XML file of records from our collections management database (developed by a company that's now out of business), I need to sort the many records in the exported XML file before converting them to EAD descriptions. The exported records are very long and complex, so I thought the best way to sort them would be to do an identity transform -- copy all the records in full to the resulting document -- but sort those copied records by the first personal or corporate name in each record. I can't figure out how to do that, simple as it seems. Here's a snippet of the exported source doc. Each "record" is defined by <TitleWork> tags (each TitleWork element set will be converted to an EAD <c01>).

<?xml version="1.0" encoding="UTF-8"?>
<mavis xmlns:xl="http://www.w3.org/1999/xlink" objectCount="10" exportLimit="0">
<rootElement>
    <TitleWork>
        ...[a lot of elements here]...
        <roles>
            <Name-Role>
                <party xl:href="/Name/key/2708" xl:title="Smith, John"/>
                <principalRole>N</principalRole>
                <role xl:href="/Code/key/ROLE//INE" xl:title="Interviewee">INE</role>
            </Name-Role>
            <Name-Role>
                <party xl:href="/Person/key/279613-1" xl:title="Johnson, Joe"/>
                <principalRole>N</principalRole>
                <role xl:href="/Code/key/ROLE//INE" xl:title="Interviewee">INE</role>
            </Name-Role>
        </roles>
        ...
    </TitleWork>
... [more TitleWork records here] ...
</mavis>

Sometimes there are 3-4 //party elements in a TitleWork record; I want to sort the complete XML document of records by the name in each TitleWork record's first party element/@xl:title attribute  (i.e., sort on the value of //party[1]/@xl:title). Here's one of my failed stylesheets. I've tried <xsl:for-each> for sorting, too -- no luck.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:xl="http://www.w3.org/1999/xlink">
    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="no"></xsl:output>
    <xsl:strip-space elements="*"></xsl:strip-space>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"></xsl:apply-templates>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="//TitleWork">
        <xsl:apply-templates>
            <xsl:sort select="//party[1]/@xl:title"></xsl:sort>
        </xsl:apply-templates>
    </xsl:template>
</xsl:stylesheet>

Any help deeply appreciated! Many thanks.

Marsha Maguire