xsl-list
[Top] [All Lists]

Re: [xsl] Aligning/merging two sequences

2010-09-30 14:18:38
Thank you very, very much indeed, Martin—this does exactly what it's supposed to do. My issue was with keeping proper track of the number of skipped items.

M.

Martin Honnen wrote:
Martin Honnen wrote:
Markus Flatscher wrote:

I.e., for each input1//w, @n should be copied to the nearest following sibling <w> in input2 that matches .; <w>s in input2 that aren't in input1 should be flagged as "skipped".


Here is a second attempt, more like what I wanted to implement

<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
exclude-result-prefixes="xs">

<xsl:param name="inp1" as="xs:string" select="'input1.xml'"/>
<xsl:variable name="input1" as="element(input1)" select="document($inp1)/input1"/>

<xsl:output method="xml" indent="yes"/>

<xsl:template match="input2">
<output>
<xsl:apply-templates select="w[1]">
<xsl:with-param name="skipped" select="0"/>
</xsl:apply-templates>
</output>
</xsl:template>

<xsl:template match="input2/w">
<xsl:param name="skipped" as="xs:integer"/>
<xsl:variable name="pos" as="xs:integer"><xsl:number/></xsl:variable>
<xsl:variable name="match" select="$input1/w[$pos - $skipped][. = current()]"/>
<w n="{if ($match) then $match/@n else 'skipped'}">
<xsl:value-of select="."/>
</w>
<xsl:apply-templates select="following-sibling::w[1]">
<xsl:with-param name="skipped" select="if ($match) then $skipped else $skipped + 1"/>
</xsl:apply-templates>
</xsl:template>

</xsl:stylesheet>




--
Markus Flatscher, Project Editor
ROTUNDA, The University of Virginia Press
PO Box 400314, Charlottesville VA 22904, USA
Courier: 211 Emmet Street South, Charlottesville VA 22903, USA
Email: markus(_dot_)flatscher(_at_)virginia(_dot_)edu
Web: http://rotunda.upress.virginia.edu/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>