comparison software/mpdl-services/mpiwg-mpdl-xml/bin/de/mpg/mpiwg/berlin/mpdl/xml/transform/getFragment.xsl @ 23:e845310098ba

diverse Korrekturen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 27 Nov 2012 12:35:19 +0100
parents
children
comparison
equal deleted inserted replaced
22:6a45a982c333 23:e845310098ba
1 <?xml version="1.0"?>
2 <!-- Delivers the fragment between two milestones. Takes no care about namespaces. -->
3
4 <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="local-function">
5
6 <xsl:function name="fn:contains">
7 <xsl:param name="sequence" as="node()*"/>
8 <xsl:param name="node" as="node()?"/>
9 <xsl:sequence select="some $nodeInSequence in $sequence satisfies $nodeInSequence is $node"/>
10 </xsl:function>
11
12 <xsl:output method="xml" encoding="utf-8"/>
13
14 <!-- ms1Name and ms2Name have to be given without namespace: e.g. "pb" -->
15 <xsl:param name="ms1Name"></xsl:param>
16 <xsl:param name="ms1Position"></xsl:param>
17 <xsl:param name="ms2Name"></xsl:param>
18 <xsl:param name="ms2Position"></xsl:param>
19
20 <xsl:variable name="ms1XPath" select="concat('subsequence(//*:', $ms1Name, ', ', $ms1Position, ', 1)')"/>
21 <xsl:variable name="ms2XPath" select="concat('subsequence(//*:', $ms2Name, ', ', $ms2Position, ', 1)')"/>
22 <xsl:variable name="ms1" select="saxon:evaluate($ms1XPath)" xmlns:saxon="http://saxon.sf.net/"/>
23 <xsl:variable name="ms2" select="saxon:evaluate($ms2XPath)" xmlns:saxon="http://saxon.sf.net/"/>
24 <xsl:variable name="ms1Ancestors" select="$ms1/ancestor::*"/>
25 <xsl:variable name="ms2Ancestors" select="$ms2/ancestor::*"/>
26
27 <!-- all elements between the milestone elements and also the ancestor elements (for filling the node path to the root) -->
28 <xsl:template match="element()[local-name() != $ms1Name and local-name() != $ms2Name]">
29 <xsl:choose>
30 <xsl:when test="(. >> $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 >> . or fn:contains($ms2Ancestors, .))">
31 <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of><xsl:apply-templates/></xsl:element>
32 </xsl:when>
33 <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
34 </xsl:choose>
35 </xsl:template>
36
37 <!-- the two milestone elements -->
38 <xsl:template match="element()[local-name() = $ms1Name or local-name() = $ms2Name]">
39 <xsl:choose>
40 <xsl:when test=". is $ms1">
41 <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
42 </xsl:when>
43 <xsl:when test=". is $ms2">
44 <xsl:element name="{local-name(.)}"><xsl:copy-of select="@*"></xsl:copy-of></xsl:element>
45 </xsl:when>
46 <xsl:otherwise></xsl:otherwise>
47 </xsl:choose>
48 </xsl:template>
49
50 <xsl:template match="attribute()|text()|comment()|processing-instruction()">
51 <xsl:choose>
52 <xsl:when test=". >> $ms1 and $ms2 >> .">
53 <xsl:copy><xsl:apply-templates/></xsl:copy>
54 </xsl:when>
55 <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
56 </xsl:choose>
57 </xsl:template>
58
59 </xsl:stylesheet>