OAI - resumption Token - xsl:iterate

Here should go questions about transforming XML with XSLT and FOP.
Andreas
Posts: 12
Joined: Wed Jan 16, 2019 6:49 pm

OAI - resumption Token - xsl:iterate

Post by Andreas »

Hello!
I am processing data records from an OAI interface such as https://services.dnb.de/oai/repository? ... 2023-12-01 .

The individual record elements must be processed after a Catalog title is established.

At the end of the list is a resumptionToken, which can be used to call the next page of the result query. ( ) (https://www.dnb.de/EN/Professionell/Met ... 2_akk.html )

How can I use xsl:iterate to build a query that retrieves all pages with the new resumptionToken?

Here is a rough draft:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="3.0" xmlns:oai="http://www.openarchives.org/OAI/2.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:strip-space elements="*"/>

  <xsl:output method="xml" indent="no" encoding="UTF-8"/>

  <xsl:param name="param-uri-file-source" select="'https://services.dnb.de/oai/repository?verb=ListRecords&amp;metadataPrefix=oai_dc'"/>

  <xsl:variable name="file-source">
    <xsl:choose>
      <xsl:when test="doc-available($param-uri-file-source)">
        <xsl:copy-of select="doc($param-uri-file-source)"/>
      </xsl:when>
      <xsl:when test="starts-with($param-uri-file-source,'http')">
        <xsl:variable name="http">
          <xsl:call-template name="get-file-from-interface">
            <xsl:with-param name="uri-base-interface" select="$param-uri-file-source"/>
          </xsl:call-template>
        </xsl:variable>
        <xsl:if test="doc-available($http)">
          <xsl:copy-of select="doc($param-uri-file-source)"/>
        </xsl:if>
      </xsl:when>
    </xsl:choose>
  </xsl:variable>

  <xsl:template match="/">
    <xsl:result-document method="xml" indent="no" encoding="UTF-8">

      <recordMetadata>
        <Catalog>
          <title>
            <xsl:value-of select="'Catalog Title'"/>
          </title>
        </Catalog>

        <!-- Iteration -->
        <xsl:iterate select="$file-source/oai:OAI-PMH/oai:ListRecords">

          <xsl:param name="param-resumptionToken"/>

          <xsl:for-each select="oai:record">

            <xsl:variable name="record" select="copy-of(.)"/>

            <Titel>
              <xsl:value-of select="$record/dc:title"/>
            </Titel>

          </xsl:for-each>

          <xsl:if test="position() = last() and oai:resumptionToken != ''">
            <xsl:next-iteration>
              <xsl:with-param name="param-resumptionToken" select="oai:resumptionToken"/>
            </xsl:next-iteration>
          </xsl:if>

        </xsl:iterate>

      </recordMetadata>
    </xsl:result-document>

  </xsl:template>
How can I iterate with the resumption tokens?

Thanks for your help!
Martin Honnen
Posts: 95
Joined: Tue Aug 19, 2014 12:04 pm

Re: OAI - resumption Token - xsl:iterate

Post by Martin Honnen »

I would consider a recursive function e.g.

Code: Select all

<xsl:function name="mf:process-records" as="node()*">
   <xsl:param name="recordList" as="element(oai:ListRecords)"/>
   <xsl:for-each select="oai:record">
       <xsl:variable name="record" select="copy-of(.)"/>
        <Titel>
              <xsl:value-of select="$record/dc:title"/>
         </Titel>
   </xsl:for-each>
   <xsl:if test="oai:resumptionToken">
      <xsl:sequence select="mf:process-records(doc($param-uri-file-source || '&amp;resumptionToken=' || oai:resumptionToken)/oai:OAI-PMH/oai:ListRecords)"/>
  </xsl:if>
</xsl:function>
Then call e.g.

Code: Select all

<xsl:sequence select="mf:process-records($file-source/oai:OAI-PMH/oai:ListRecords)"/>
Post Reply