Skip to content

Instantly share code, notes, and snippets.

@CJHArch
Created January 12, 2015 21:30
Show Gist options
  • Save CJHArch/190dad378a3600021e76 to your computer and use it in GitHub Desktop.
Save CJHArch/190dad378a3600021e76 to your computer and use it in GitHub Desktop.
Automatically adding and filling <dao> fields when the ingest PIDs are in the same order as the container list
<?xml version="1.0" encoding="UTF-8"?>
<!-- This stylesheet will add daos to a finding aid, using a list of PIDs. -->
<!-- One needs to select one of the two templates below, depending on whether the daos are to be added to all c0x level=file elements or just to a certain subset -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>
<!-- Call PID file -->
<xsl:variable name="data" select="document('PIDList.xml')"/>
<!-- Identity template copies everything except templates below -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- First template -->
<!-- Looks at file levels. Adds dao with URL template to every c0x with a file attribute-->
<xsl:template match="*[@level='file']/did">
<xsl:for-each select=".">
<xsl:variable name="count">
<xsl:value-of select="count(../preceding-sibling::*[@level='file']) + 1"/>
</xsl:variable>
<xsl:copy-of select="."/>
<xsl:element name="dao">
<xsl:attribute name="href">
<xsl:text>http://digital.cjh.org/webclient/DeliveryManager?pid=</xsl:text>
<xsl:value-of select="$data/data/pid[number($count)]"/>
</xsl:attribute>
<xsl:attribute name="linktype">simple</xsl:attribute>
<xsl:attribute name="actuate">onrequest</xsl:attribute>
<xsl:attribute name="show">new</xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:template>
<!-- Second template: with limiting test in the template match. Define this as needed in the first line; here for example, it's only going to add daos to the second instance of c01. Looks at file levels. Adds dao with URL template to every c0x with a file attribute -->
<!-- <xsl:template match="//c01[2]/*[@level='file']/did">
<xsl:for-each select=".">
<xsl:variable name="count">
<xsl:value-of select="count(../preceding-sibling::*[@level='file']) + 1"/>
</xsl:variable>
<xsl:copy-of select="."/>
<xsl:element name="dao">
<xsl:attribute name="href">
<xsl:text>http://digital.cjh.org/webclient/DeliveryManager?pid=</xsl:text>
<xsl:value-of select="$data/data/pid[number($count)]"/>
</xsl:attribute>
<xsl:attribute name="linktype">simple</xsl:attribute>
<xsl:attribute name="actuate">onrequest</xsl:attribute>
<xsl:attribute name="show">new</xsl:attribute>
</xsl:element>
</xsl:for-each>
</xsl:template>
-->
</xsl:stylesheet>
<data>
<pid>12345</pid>
<pid>67890123</pid>
<pid>ABCDEEEEEE</pid>
<pid>FGHEIIIIIIIII</pid>
</data>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment