Help! only last pass of p:for-each being used

Hi List,

Apologies in advance for the long code listing: I'm in a bit of a rush and don't have the time to write pseudo-code (I just hope some kind soul is around to take pity on me)!

I have a pipeline to fix errors in a conversion process between two DTDs.  The original xml had a graphic element like this:

	<graphic id="t-graphic-4" type="display">
	  <file id="t-file-4">9780195175929.andalusia.3.jpg</file>
	  <cap>Court of Lions of the Alhambra palace of Granada <src>John and Lisa Merrill/Corbis</src></cap>
	</graphic>

The converted XML should look like this:

	<figureGroup id="acref-9780195165203-figureGroup-0004">
	  <figure>
	    <graphic id="t-file-4" fileName="9780195175929.andalusia.3.jpg"/>
	    <caption><p>Court of Lions of the Alhambra palace of Granada <span role="source">John and Lisa Merrill/Corbis</span></p></caption>
	  </figure>
	</figureGroup>

But it missing the correct caption, like this:

	<figureGroup id="acref-9780195165203-figureGroup-0004">
	  <figure>
	    <caption><p/></caption>
	    <graphic id="t-file-4" fileName="9780195175929.andalusia.3.jpg"/>
	  </figure>
	</figureGroup>

I've written a pipeline which goes through the original file (named something like t94.xml), stores the file name of the graphic for each //graphic[cap], creates the proper format of <caption> and (theoretically) inserts this xml at the relevant point after the corresponding graphic element in the converted file (named something like t94-transformed-spaceFixed.xml). The pipeline inserts and saves within the foreach //graphic[cap] - or at least I think it should!

The issue is that although the pipeline is correctly producing the new <caption> elements for every //graphic in the original file, it's only doing the processing on the converted file for //graphic[last()]...  I don't understand why this should be!

I'm running calabash through oXygen.

Tom

Here's the xproc:

__________________________
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:law="http://dtd.oup.com/law/" xmlns:oxp="http://dtg.oup.com/xproc" version="1.0" name="re-add-captions" exclude-inline-prefixes="c p oxp law">

    <p:input port="source">
        <p:empty/>
    </p:input>
    <p:output port="result" sequence="true"/>

    <p:option name="dir" select="."/>

    <p:directory-list>
        <p:with-option name="path" select="$dir"/>
    </p:directory-list>
    <p:filter select="//c:file[contains(@name, '.xml') and not(contains(@name, '-transformed-spaceFixed'))]"/>

    <p:for-each>
        <p:variable name="href1" select="concat($dir, '/', replace(c:file/@name, '\s', '%20'))"/>
        <p:variable name="hrefOut" select="concat(substring-before(concat($dir, '/', replace(c:file/@name, '\s', '%20')), '.xml'), '-transformed-spaceFixed.xml')"/>
        <p:load dtd-validate="false">
            <p:with-option name="href" select="$href1"/>
        </p:load>
        <p:filter select="//graphic[cap]"/>
        <p:for-each>
            <p:variable name="figureName" select="//file[1]"/>
            <p:filter select="//cap[1]"/>
            <p:identity name="caps"/>
            <p:xslt><!-- converts cap to caption, src to span[@role="source"] and title to titleGroup/title/p -->
                <p:input port="stylesheet">
                    <p:inline>
                        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xml:space="preserve">
                            <xsl:template match="cap" xml:space="preserve"><caption><p><xsl:apply-templates/></p></caption></xsl:template>
                            <xsl:template match="src"><span role="source"><xsl:apply-templates/></span></xsl:template>
                            <xsl:template match="title"><titleGroup><title><p><xsl:apply-templates/></p></title></titleGroup></xsl:template>
                            <xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template>
                        </xsl:stylesheet>
                    </p:inline>
                </p:input>
                <p:input port="parameters">
                    <p:empty/>
                </p:input>
            </p:xslt>
            <p:xslt><!-- replaces <p>{1}<para/>{2}</p> with <p>{1}</p><p>{2}</p> -->
                <p:input port="stylesheet">
                    <p:inline>
                        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xml:space="preserve">
                            <xsl:template match="//p/node()[preceding-sibling::para[not(child::*)] or following-sibling::para[not(child::*)]]"><p><xsl:copy><xsl:apply-templates/></xsl:copy></p></xsl:template>
                            <xsl:template match="//p[node()[preceding-sibling::para[not(child::*)] or following-sibling::para[not(child::*)]]]"><xsl:apply-templates/></xsl:template>
                            <xsl:template match="//para[not(child::*)]"><xsl:apply-templates/></xsl:template>
                            <xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template>
                        </xsl:stylesheet>
                    </p:inline>
                </p:input>
                <p:input port="parameters">
                    <p:empty/>
                </p:input>
            </p:xslt>
            <p:identity name="caption"/>
            <p:load>
                <p:with-option name="href" select="$hrefOut"/>
            </p:load>
            <!-- remove existing empty caption[following-sibling::graphic] -->
            <p:delete match="//figure/caption[following-sibling::graphic]"/>
            <p:identity name="placeholder1"/>
            <!-- also remove existing target so pipeline can be run multiple times without creating dupes -->
            <p:delete>
                <p:with-option name="match" select="concat('//figure[graphic/@fileName=', '&quot;', $figureName, '&quot;', ']/caption')"/>
            </p:delete>
            <!-- insert caption from original file in correct place -->
            <p:insert position="after">
                <p:with-option name="match" select="concat('//figure/graphic[@fileName=', '&quot;', $figureName, '&quot;', ']')"/>
                <p:input port="insertion">
                    <p:pipe port="result" step="caption"/>
                </p:input>
                <p:input port="source">
                    <p:pipe port="result" step="placeholder1"/>
                </p:input>
            </p:insert>
            <p:xslt><!-- remove default attributes of p -->
                <p:input port="stylesheet">
                    <p:inline>
                        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xml:space="preserve">
                            <xsl:template match="@*[name() = 'continued' or name() = 'fullOut' or name() = 'runin'][. = 'N']"/>
                            <xsl:template match="@*[name() = 'purpose'][. = 'display']"/>
                            <xsl:template match="@*[name() = 'electronicRight'][. = 'Y']"/>
                            <xsl:template match="@*[name() = 'placement'][. = 'fixed']"/>
                            <xsl:template match="@*[name() = 'orient'][. = 'port']"/>
                            <xsl:template match="ONIXMessage/@release"/>
                            <xsl:template match="@*[name() = 'refname' and ancestor::ONIXMessage]"/>
                            <xsl:template match="node()|@*"><xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy></xsl:template>
                            <xsl:template match="/"><xsl:apply-templates/></xsl:template>
                        </xsl:stylesheet>
                    </p:inline>
                </p:input>
                <p:input port="parameters"><p:empty/></p:input>
            </p:xslt>
            <!-- save and purge file -->
            <p:store omit-xml-declaration="false" encoding="UTF-8" doctype-public="-//OXFORD//DTD OXENCYCLML//EN" doctype-system="OxEncyclML.dtd" name="saveFiles">
                <p:with-option name="href" select="$hrefOut"/>
            </p:store>
            <p:identity>
                <p:input port="source">
                    <p:pipe port="result" step="caption"/>
                </p:input>
            </p:identity>
            <p:add-attribute attribute-name="figureName" match="//caption">
                <p:with-option name="attribute-value" select="$figureName"/>
            </p:add-attribute>
            <!--<p:add-attribute attribute-name="href1" match="//caption">
                <p:with-option name="attribute-value" select="$href1"/>
            </p:add-attribute>
            <p:add-attribute attribute-name="hrefout" match="//caption">
                <p:with-option name="attribute-value" select="$hrefOut"/>
            </p:add-attribute>-->
        </p:for-each>
    </p:for-each>

</p:declare-step>
Oxford University Press (UK) Disclaimer

This message is confidential. You should not copy it or disclose its contents to anyone. You may use and apply the information for the intended purpose only. OUP does not accept legal responsibility for the contents of this message. Any views or opinions presented are those of the author only and not of OUP. If this email has come to you in error, please delete it, along with any attachments. Please note that OUP may intercept incoming and outgoing email communications.

Received on Thursday, 12 August 2010 18:20:05 UTC