<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.tei-c.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joey</id>
	<title>TEIWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.tei-c.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Joey"/>
	<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=Special:Contributions/Joey"/>
	<updated>2026-04-19T03:55:44Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9659</id>
		<title>GetFragment.xsl</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9659"/>
		<updated>2011-07-12T13:18:05Z</updated>

		<summary type="html">&lt;p&gt;Joey: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:XSLT]]&lt;br /&gt;
== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| Josef Willenborg, Max Planck Institute for the History of Science, [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2011-07-12&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
Returns an xml fragment between two milestone elements. The result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
== Required input ==&lt;br /&gt;
XSLT parameters:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
* ms1Name (first milestone name): &amp;quot;pb&amp;quot;&lt;br /&gt;
* ms1Position (first milestone position): 1&lt;br /&gt;
* ms2Name (second milestone name): &amp;quot;pb&amp;quot;&lt;br /&gt;
* ms2Position (second milestone position): 2&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
XML document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;TEI xmlns=&amp;quot;http://www.tei-c.org/ns/1.0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;pb n=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;p&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the first sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the second sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the third &amp;lt;pb n=&amp;quot;2&amp;quot;/&amp;gt;sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
      &amp;lt;/p&amp;gt;&lt;br /&gt;
      &lt;br /&gt;
      &amp;lt;p&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the first sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the second sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the third sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
      &amp;lt;/p&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Expected output ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;TEI&amp;gt;&lt;br /&gt;
   &amp;lt;text&amp;gt;&lt;br /&gt;
      &amp;lt;body&amp;gt;&lt;br /&gt;
         &amp;lt;pb n=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;p&amp;gt;&lt;br /&gt;
            &amp;lt;s&amp;gt;This is the first sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
            &amp;lt;s&amp;gt;This is the second sentence.&amp;lt;/s&amp;gt;&lt;br /&gt;
            &amp;lt;s&amp;gt;This is the third &amp;lt;pb n=&amp;quot;2&amp;quot;/&amp;gt;&lt;br /&gt;
            &amp;lt;/s&amp;gt;&lt;br /&gt;
         &amp;lt;/p&amp;gt;&lt;br /&gt;
      &amp;lt;/body&amp;gt;&lt;br /&gt;
   &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restrictions ==&lt;br /&gt;
* uses the Saxon extension function [http://www.saxonica.com/documentation/extensions/functions/evaluate.xml &amp;quot;saxon:evaluate&amp;quot;] (so the Saxon library is needed for this)&lt;br /&gt;
* takes no care about namespaces&lt;br /&gt;
* wrapping into parent node cannot be configured&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!-- Delivers the fragment between two milestones. Takes no care about namespaces. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:stylesheet version=&amp;quot;2.0&amp;quot; xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot; xmlns:fn=&amp;quot;local-function&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name=&amp;quot;fn:contains&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;sequence&amp;quot; as=&amp;quot;node()*&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;node&amp;quot; as=&amp;quot;node()?&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:sequence select=&amp;quot;some $nodeInSequence in $sequence satisfies $nodeInSequence is $node&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:output method=&amp;quot;xml&amp;quot; encoding=&amp;quot;utf-8&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ms1Name and ms2Name have to be given without namespace: e.g. &amp;quot;pb&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms1Name, ', ', $ms1Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms2Name, ', ', $ms2Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1&amp;quot; select=&amp;quot;saxon:evaluate($ms1XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2&amp;quot; select=&amp;quot;saxon:evaluate($ms2XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1Ancestors&amp;quot; select=&amp;quot;$ms1/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2Ancestors&amp;quot; select=&amp;quot;$ms2/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() != $ms1Name and local-name() != $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;(. &amp;gt;&amp;gt; $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 &amp;gt;&amp;gt; . or fn:contains($ms2Ancestors, .))&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;attribute()|text()|comment()|processing-instruction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. &amp;gt;&amp;gt; $ms1 and $ms2 &amp;gt;&amp;gt; .&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:copy&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() = $ms1Name or local-name() = $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms2&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9658</id>
		<title>GetFragment.xsl</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9658"/>
		<updated>2011-07-12T13:08:22Z</updated>

		<summary type="html">&lt;p&gt;Joey: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:XSLT]]&lt;br /&gt;
== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| Josef Willenborg, Max Planck Institute for the History of Science, [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2011-07-12&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
Returns an xml fragment between two milestone elements. The result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
== Required input ==&lt;br /&gt;
XSLT parameters:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
* ms1Name (first milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms1Position (first milestone position: e.g. 1)&lt;br /&gt;
* ms2Name (second milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms2Position (second milestone position: e.g. 2)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
XML document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;TEI xmlns=&amp;quot;http://www.tei-c.org/ns/1.0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;pb n=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;p&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the first sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the second sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the third sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
      &amp;lt;/p&amp;gt;&lt;br /&gt;
      &amp;lt;pb n=&amp;quot;2&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;p&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the first sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the second sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the third sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
      &amp;lt;/p&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Expected output ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;TEI&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;pb n=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
      &amp;lt;p&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the first sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the second sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
        &amp;lt;s&amp;gt;This is the third sentence of the first paragraph.&amp;lt;/s&amp;gt;&lt;br /&gt;
      &amp;lt;/p&amp;gt;&lt;br /&gt;
      &amp;lt;pb n=&amp;quot;2&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Restrictions ==&lt;br /&gt;
* uses the Saxon extension function [http://www.saxonica.com/documentation/extensions/functions/evaluate.xml &amp;quot;saxon:evaluate&amp;quot;] (so the Saxon library is needed for this)&lt;br /&gt;
* takes no care about namespaces&lt;br /&gt;
* wrapping into parent node cannot be configured&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!-- Delivers the fragment between two milestones. Takes no care about namespaces. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:stylesheet version=&amp;quot;2.0&amp;quot; xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot; xmlns:fn=&amp;quot;local-function&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name=&amp;quot;fn:contains&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;sequence&amp;quot; as=&amp;quot;node()*&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;node&amp;quot; as=&amp;quot;node()?&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:sequence select=&amp;quot;some $nodeInSequence in $sequence satisfies $nodeInSequence is $node&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:output method=&amp;quot;xml&amp;quot; encoding=&amp;quot;utf-8&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ms1Name and ms2Name have to be given without namespace: e.g. &amp;quot;pb&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms1Name, ', ', $ms1Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms2Name, ', ', $ms2Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1&amp;quot; select=&amp;quot;saxon:evaluate($ms1XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2&amp;quot; select=&amp;quot;saxon:evaluate($ms2XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1Ancestors&amp;quot; select=&amp;quot;$ms1/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2Ancestors&amp;quot; select=&amp;quot;$ms2/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() != $ms1Name and local-name() != $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;(. &amp;gt;&amp;gt; $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 &amp;gt;&amp;gt; . or fn:contains($ms2Ancestors, .))&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;attribute()|text()|comment()|processing-instruction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. &amp;gt;&amp;gt; $ms1 and $ms2 &amp;gt;&amp;gt; .&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:copy&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() = $ms1Name or local-name() = $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms2&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9657</id>
		<title>GetFragment.xsl</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=GetFragment.xsl&amp;diff=9657"/>
		<updated>2011-07-12T12:49:49Z</updated>

		<summary type="html">&lt;p&gt;Joey: New page: == Authorship == {|  | ''Author'' | Josef Willenborg, Max Planck Institute for the History of Science, [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de] |-  | ''Last...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| Josef Willenborg, Max Planck Institute for the History of Science, [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2011-07-12&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
Input of the transformation script is the XML document of which a fragment should be extracted. Parameters of the transformation script are:&lt;br /&gt;
* ms1Name (first milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms1Position (first milestone position: e.g. 5)&lt;br /&gt;
* ms2Name (second milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms2Position (second milestone position: e.g. 6)&lt;br /&gt;
It returns an xml fragment between two milestone elements. The result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
== Restrictions ==&lt;br /&gt;
* uses the Saxon extension function [http://www.saxonica.com/documentation/extensions/functions/evaluate.xml &amp;quot;saxon:evaluate&amp;quot;] (so the Saxon library is needed for this)&lt;br /&gt;
* takes no care about namespaces&lt;br /&gt;
* wrapping into parent node cannot be configured&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!-- Delivers the fragment between two milestones. Takes no care about namespaces. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:stylesheet version=&amp;quot;2.0&amp;quot; xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot; xmlns:fn=&amp;quot;local-function&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name=&amp;quot;fn:contains&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;sequence&amp;quot; as=&amp;quot;node()*&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;node&amp;quot; as=&amp;quot;node()?&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:sequence select=&amp;quot;some $nodeInSequence in $sequence satisfies $nodeInSequence is $node&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:output method=&amp;quot;xml&amp;quot; encoding=&amp;quot;utf-8&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ms1Name and ms2Name have to be given without namespace: e.g. &amp;quot;pb&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms1Name, ', ', $ms1Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms2Name, ', ', $ms2Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1&amp;quot; select=&amp;quot;saxon:evaluate($ms1XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2&amp;quot; select=&amp;quot;saxon:evaluate($ms2XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1Ancestors&amp;quot; select=&amp;quot;$ms1/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2Ancestors&amp;quot; select=&amp;quot;$ms2/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() != $ms1Name and local-name() != $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;(. &amp;gt;&amp;gt; $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 &amp;gt;&amp;gt; . or fn:contains($ms2Ancestors, .))&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;attribute()|text()|comment()|processing-instruction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. &amp;gt;&amp;gt; $ms1 and $ms2 &amp;gt;&amp;gt; .&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:copy&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() = $ms1Name or local-name() = $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms2&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=9656</id>
		<title>Milestone-chunk.xquery</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=9656"/>
		<updated>2011-07-12T12:48:45Z</updated>

		<summary type="html">&lt;p&gt;Joey: Moved XSL-Implementation to http://wiki.tei-c.org/index.php/GetFragment.xsl&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| David Sewell, University of Virginia, [mailto:dsewell@virginia.edu dsewell@virginia.edu]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2007-05-02&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This is an XQuery 1.0 function that will return all of the content between two milestone elements such as '''pb'''&lt;br /&gt;
while preserving the hierarchical structure of the containing elements. For example, given content like this in a TEI document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;TEI&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt; &amp;lt;!-- lots of div2s --&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;An example&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;pb n=&amp;quot;4&amp;quot;/&amp;gt;here.&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt; &amp;lt;!-- followed by lots of other stuff --&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the function would produce the following XML fragment as output when asked to return content between '''pb/@n=3''' and '''pb/@n=4'''&lt;br /&gt;
with the '''text''' element as the ancestor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, the full hierarchical structure of the ancestor elements, including their attributes, is preserved, but only the nodal content between the milestons is included.&lt;br /&gt;
&lt;br /&gt;
== Required Input ==&lt;br /&gt;
&lt;br /&gt;
The function signature is&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''$node''' is an element known to be a common ancestor of the two milestones. For example, it could be '''TEI/text''', or '''TEI/text/body''', or even '''TEI/text/body/div1[3]''' if the milestone parameters are both descendants of that div1.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' is the first milestone element; '''$ms2''' is the second milestone element.&lt;br /&gt;
&lt;br /&gt;
For example, the output in &amp;quot;Summary&amp;quot; above might have been produced by the call&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  return local:milestone-chunk($input//pb[@n=&amp;quot;3&amp;quot;], $input//pb[@n=&amp;quot;4&amp;quot;], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If '''$input''' had been &lt;br /&gt;
   doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text/tei:body&lt;br /&gt;
then the output would have started at the '''body''' element, etc.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' and '''$ms2''' do not need to be adjacent milestones. You can, for example, return content between '''pb/@n=4''' and '''pb/@n=7'''. Nor do the milestones need to be of the same type; you can return content between the '''pb''' for page 4 and an arbitrary anchor or pointer element later in the document.&lt;br /&gt;
&lt;br /&gt;
== Expected Output ==&lt;br /&gt;
&lt;br /&gt;
As indicated in the example in &amp;quot;Summary&amp;quot; above, the output should be a single XML element reflecting the structure of the input ancestor element and its descendants, but otherwise containing only the nodal content between the two milestone elements in the original input.&lt;br /&gt;
&lt;br /&gt;
== Known Restrictions or Problems ==&lt;br /&gt;
The output will contain a copy of the first milestone element, but not of the second (closing) one. This is a consequence of the need to use pseudo-milestones for the second milestone in some cases; see next paragraph. &lt;br /&gt;
&lt;br /&gt;
When using this function to generate content between TEI '''pb''' elements, an obvious problem is that the final page will not have a final '''pb''' milestone. In this case, use a pseudo-milestone such as the last node in the input element. For example, using the sample document in &amp;quot;Summary&amp;quot; above, the content of page 4 (&amp;quot;here.&amp;quot;) would be output via the call&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  local:milestone-chunk($input//pb[@n=&amp;quot;4&amp;quot;], ($input//node())[last()], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you use this function to recurse over all the '''pb''' elements in a document, you will need to use a strategy like this when '''$ms1''' has no following '''pb''' element.&lt;br /&gt;
&lt;br /&gt;
The function will not gracefully handle invalid input, but will probably throw run-time errors. You should be sure that the parameters passed to it reflect actual milestone elements with a common ancestor.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
declare function local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
) as node()*&lt;br /&gt;
{&lt;br /&gt;
  typeswitch ($node)&lt;br /&gt;
    case element() return&lt;br /&gt;
      if ($node is $ms1) then $node&lt;br /&gt;
      else if ( some $n in $node/descendant::* satisfies ($n is $ms1 or $n is $ms2) )&lt;br /&gt;
      then&lt;br /&gt;
        element { name($node) }&lt;br /&gt;
                { for $i in ( $node/node() | $node/@* )&lt;br /&gt;
                  return local:milestone-chunk($ms1, $ms2, $i) }&lt;br /&gt;
      else if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
    case attribute() return $node (: will never match attributes outside non-returned elements :)&lt;br /&gt;
    default return &lt;br /&gt;
      if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementation in eXist ==&lt;br /&gt;
This function is implemented in [[eXist]] (as a function called [http://demo.exist-db.org/exist/functions/util/get-fragment-between util:get-fragment-between()]) by Josef Willenborg, Max Planck Institute for the History of Science [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
util:get-fragment-between($beginning-node as node()?, $ending-node as node()?, $make-fragment as xs:boolean?) xs:string&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns an xml fragment or a sequence of nodes between two elements (normally milestone elements). The $beginning-node represents the first node/milestone element, $ending-node, the second one. The third argument, $make-fragment, is a boolean value for the path completion. If it is set to true() the result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
Example call of the function for getting the fragment between two TEI page break element nodes: &lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
let $fragment := util:get-fragment-between(//pb[1], //pb[2], true())&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:XQuery]]&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=9655</id>
		<title>Milestone-chunk.xquery</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=9655"/>
		<updated>2011-07-12T12:33:42Z</updated>

		<summary type="html">&lt;p&gt;Joey: added XSL-Implementation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| David Sewell, University of Virginia, [mailto:dsewell@virginia.edu dsewell@virginia.edu]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2007-05-02&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This is an XQuery 1.0 function that will return all of the content between two milestone elements such as '''pb'''&lt;br /&gt;
while preserving the hierarchical structure of the containing elements. For example, given content like this in a TEI document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;TEI&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt; &amp;lt;!-- lots of div2s --&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;An example&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;pb n=&amp;quot;4&amp;quot;/&amp;gt;here.&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt; &amp;lt;!-- followed by lots of other stuff --&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the function would produce the following XML fragment as output when asked to return content between '''pb/@n=3''' and '''pb/@n=4'''&lt;br /&gt;
with the '''text''' element as the ancestor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, the full hierarchical structure of the ancestor elements, including their attributes, is preserved, but only the nodal content between the milestons is included.&lt;br /&gt;
&lt;br /&gt;
== Required Input ==&lt;br /&gt;
&lt;br /&gt;
The function signature is&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''$node''' is an element known to be a common ancestor of the two milestones. For example, it could be '''TEI/text''', or '''TEI/text/body''', or even '''TEI/text/body/div1[3]''' if the milestone parameters are both descendants of that div1.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' is the first milestone element; '''$ms2''' is the second milestone element.&lt;br /&gt;
&lt;br /&gt;
For example, the output in &amp;quot;Summary&amp;quot; above might have been produced by the call&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  return local:milestone-chunk($input//pb[@n=&amp;quot;3&amp;quot;], $input//pb[@n=&amp;quot;4&amp;quot;], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If '''$input''' had been &lt;br /&gt;
   doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text/tei:body&lt;br /&gt;
then the output would have started at the '''body''' element, etc.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' and '''$ms2''' do not need to be adjacent milestones. You can, for example, return content between '''pb/@n=4''' and '''pb/@n=7'''. Nor do the milestones need to be of the same type; you can return content between the '''pb''' for page 4 and an arbitrary anchor or pointer element later in the document.&lt;br /&gt;
&lt;br /&gt;
== Expected Output ==&lt;br /&gt;
&lt;br /&gt;
As indicated in the example in &amp;quot;Summary&amp;quot; above, the output should be a single XML element reflecting the structure of the input ancestor element and its descendants, but otherwise containing only the nodal content between the two milestone elements in the original input.&lt;br /&gt;
&lt;br /&gt;
== Known Restrictions or Problems ==&lt;br /&gt;
The output will contain a copy of the first milestone element, but not of the second (closing) one. This is a consequence of the need to use pseudo-milestones for the second milestone in some cases; see next paragraph. &lt;br /&gt;
&lt;br /&gt;
When using this function to generate content between TEI '''pb''' elements, an obvious problem is that the final page will not have a final '''pb''' milestone. In this case, use a pseudo-milestone such as the last node in the input element. For example, using the sample document in &amp;quot;Summary&amp;quot; above, the content of page 4 (&amp;quot;here.&amp;quot;) would be output via the call&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  local:milestone-chunk($input//pb[@n=&amp;quot;4&amp;quot;], ($input//node())[last()], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you use this function to recurse over all the '''pb''' elements in a document, you will need to use a strategy like this when '''$ms1''' has no following '''pb''' element.&lt;br /&gt;
&lt;br /&gt;
The function will not gracefully handle invalid input, but will probably throw run-time errors. You should be sure that the parameters passed to it reflect actual milestone elements with a common ancestor.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
declare function local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
) as node()*&lt;br /&gt;
{&lt;br /&gt;
  typeswitch ($node)&lt;br /&gt;
    case element() return&lt;br /&gt;
      if ($node is $ms1) then $node&lt;br /&gt;
      else if ( some $n in $node/descendant::* satisfies ($n is $ms1 or $n is $ms2) )&lt;br /&gt;
      then&lt;br /&gt;
        element { name($node) }&lt;br /&gt;
                { for $i in ( $node/node() | $node/@* )&lt;br /&gt;
                  return local:milestone-chunk($ms1, $ms2, $i) }&lt;br /&gt;
      else if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
    case attribute() return $node (: will never match attributes outside non-returned elements :)&lt;br /&gt;
    default return &lt;br /&gt;
      if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementation in eXist ==&lt;br /&gt;
This function is implemented in [[eXist]] (as a function called [http://demo.exist-db.org/exist/functions/util/get-fragment-between util:get-fragment-between()]) by Josef Willenborg, Max Planck Institute for the History of Science [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
util:get-fragment-between($beginning-node as node()?, $ending-node as node()?, $make-fragment as xs:boolean?) xs:string&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Returns an xml fragment or a sequence of nodes between two elements (normally milestone elements). The $beginning-node represents the first node/milestone element, $ending-node, the second one. The third argument, $make-fragment, is a boolean value for the path completion. If it is set to true() the result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
Example call of the function for getting the fragment between two TEI page break element nodes: &lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
let $fragment := util:get-fragment-between(//pb[1], //pb[2], true())&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== XSL-Implementation ==&lt;br /&gt;
This function is also implemented as a XSL transformation (by Josef Willenborg, Max Planck Institute for the History of Science [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]). Input of the transformation script is the XML document of which a fragment should be extracted. Parameters of the transformation script are:&lt;br /&gt;
* ms1Name (first milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms1Position (first milestone position: e.g. 5)&lt;br /&gt;
* ms2Name (second milestone name: e.g. &amp;quot;pb&amp;quot;)&lt;br /&gt;
* ms2Position (second milestone position: e.g. 6)&lt;br /&gt;
It returns an xml fragment between two milestone elements. The result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
Restrictions: &lt;br /&gt;
* uses the Saxon extension function [http://www.saxonica.com/documentation/extensions/functions/evaluate.xml &amp;quot;saxon:evaluate&amp;quot;] (so the Saxon library is needed for this)&lt;br /&gt;
* takes no care about namespaces&lt;br /&gt;
* wrapping into parent node cannot be configured&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;!-- Delivers the fragment between two milestones. Takes no care about namespaces. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:stylesheet version=&amp;quot;2.0&amp;quot; xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot; xmlns:fn=&amp;quot;local-function&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name=&amp;quot;fn:contains&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;sequence&amp;quot; as=&amp;quot;node()*&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:param name=&amp;quot;node&amp;quot; as=&amp;quot;node()?&amp;quot;/&amp;gt; &lt;br /&gt;
  &amp;lt;xsl:sequence select=&amp;quot;some $nodeInSequence in $sequence satisfies $nodeInSequence is $node&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:output method=&amp;quot;xml&amp;quot; encoding=&amp;quot;utf-8&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ms1Name and ms2Name have to be given without namespace: e.g. &amp;quot;pb&amp;quot; --&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms1Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Name&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;ms2Position&amp;quot;&amp;gt;&amp;lt;/xsl:param&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms1Name, ', ', $ms1Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2XPath&amp;quot; select=&amp;quot;concat('subsequence(//*:', $ms2Name, ', ', $ms2Position, ', 1)')&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1&amp;quot; select=&amp;quot;saxon:evaluate($ms1XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2&amp;quot; select=&amp;quot;saxon:evaluate($ms2XPath)&amp;quot; xmlns:saxon=&amp;quot;http://saxon.sf.net/&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms1Ancestors&amp;quot; select=&amp;quot;$ms1/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name=&amp;quot;ms2Ancestors&amp;quot; select=&amp;quot;$ms2/ancestor::*&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() != $ms1Name and local-name() != $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;(. &amp;gt;&amp;gt; $ms1 or fn:contains($ms1Ancestors, .)) and ($ms2 &amp;gt;&amp;gt; . or fn:contains($ms2Ancestors, .))&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;attribute()|text()|comment()|processing-instruction()&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. &amp;gt;&amp;gt; $ms1 and $ms2 &amp;gt;&amp;gt; .&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:copy&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;xsl:apply-templates/&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;element()[local-name() = $ms1Name or local-name() = $ms2Name]&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms1&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:when test=&amp;quot;. is $ms2&amp;quot;&amp;gt;&lt;br /&gt;
      &amp;lt;xsl:element name=&amp;quot;{local-name(.)}&amp;quot;&amp;gt;&amp;lt;xsl:copy-of select=&amp;quot;@*&amp;quot;&amp;gt;&amp;lt;/xsl:copy-of&amp;gt;&amp;lt;/xsl:element&amp;gt;&lt;br /&gt;
    &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
    &amp;lt;xsl:otherwise&amp;gt;&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
  &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:XQuery]]&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=7264</id>
		<title>Milestone-chunk.xquery</title>
		<link rel="alternate" type="text/html" href="https://wiki.tei-c.org/index.php?title=Milestone-chunk.xquery&amp;diff=7264"/>
		<updated>2010-02-19T15:36:30Z</updated>

		<summary type="html">&lt;p&gt;Joey: implementation in eXist db added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Authorship ==&lt;br /&gt;
{| &lt;br /&gt;
| ''Author''&lt;br /&gt;
| David Sewell, University of Virginia, [mailto:dsewell@virginia.edu dsewell@virginia.edu]&lt;br /&gt;
|- &lt;br /&gt;
| ''Last revised''&lt;br /&gt;
| 2007-05-02&lt;br /&gt;
|-&lt;br /&gt;
| ''Previous version''&lt;br /&gt;
| none&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
This is an XQuery 1.0 function that will return all of the content between two milestone elements such as '''pb'''&lt;br /&gt;
while preserving the hierarchical structure of the containing elements. For example, given content like this in a TEI document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
&amp;lt;TEI&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt; &amp;lt;!-- lots of div2s --&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;An example&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;pb n=&amp;quot;4&amp;quot;/&amp;gt;here.&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt; &amp;lt;!-- followed by lots of other stuff --&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/TEI&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the function would produce the following XML fragment as output when asked to return content between '''pb/@n=3''' and '''pb/@n=4'''&lt;br /&gt;
with the '''text''' element as the ancestor:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  &amp;lt;text&amp;gt;&lt;br /&gt;
    &amp;lt;body&amp;gt;&lt;br /&gt;
      &amp;lt;div1 type=&amp;quot;chapter&amp;quot; n=&amp;quot;1&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;div2 xml:id=&amp;quot;doc100&amp;quot;&amp;gt;&lt;br /&gt;
          &amp;lt;p&amp;gt;&amp;lt;pb n=&amp;quot;3&amp;quot;/&amp;gt;of a &amp;lt;i&amp;gt;very&amp;lt;/i&amp;gt; short page&amp;lt;/p&amp;gt;&lt;br /&gt;
        &amp;lt;/div2&amp;gt;&lt;br /&gt;
      &amp;lt;/div1&amp;gt;&lt;br /&gt;
    &amp;lt;/body&amp;gt;&lt;br /&gt;
  &amp;lt;/text&amp;gt;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other words, the full hierarchical structure of the ancestor elements, including their attributes, is preserved, but only the nodal content between the milestons is included.&lt;br /&gt;
&lt;br /&gt;
== Required Input ==&lt;br /&gt;
&lt;br /&gt;
The function signature is&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''$node''' is an element known to be a common ancestor of the two milestones. For example, it could be '''TEI/text''', or '''TEI/text/body''', or even '''TEI/text/body/div1[3]''' if the milestone parameters are both descendants of that div1.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' is the first milestone element; '''$ms2''' is the second milestone element.&lt;br /&gt;
&lt;br /&gt;
For example, the output in &amp;quot;Summary&amp;quot; above might have been produced by the call&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  return local:milestone-chunk($input//pb[@n=&amp;quot;3&amp;quot;], $input//pb[@n=&amp;quot;4&amp;quot;], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If '''$input''' had been &lt;br /&gt;
   doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text/tei:body&lt;br /&gt;
then the output would have started at the '''body''' element, etc.&lt;br /&gt;
&lt;br /&gt;
'''$ms1''' and '''$ms2''' do not need to be adjacent milestones. You can, for example, return content between '''pb/@n=4''' and '''pb/@n=7'''. Nor do the milestones need to be of the same type; you can return content between the '''pb''' for page 4 and an arbitrary anchor or pointer element later in the document.&lt;br /&gt;
&lt;br /&gt;
== Expected Output ==&lt;br /&gt;
&lt;br /&gt;
As indicated in the example in &amp;quot;Summary&amp;quot; above, the output should be a single XML element reflecting the structure of the input ancestor element and its descendants, but otherwise containing only the nodal content between the two milestone elements in the original input.&lt;br /&gt;
&lt;br /&gt;
== Known Restrictions or Problems ==&lt;br /&gt;
The output will contain a copy of the first milestone element, but not of the second (closing) one. This is a consequence of the need to use pseudo-milestones for the second milestone in some cases; see next paragraph. &lt;br /&gt;
&lt;br /&gt;
When using this function to generate content between TEI '''pb''' elements, an obvious problem is that the final page will not have a final '''pb''' milestone. In this case, use a pseudo-milestone such as the last node in the input element. For example, using the sample document in &amp;quot;Summary&amp;quot; above, the content of page 4 (&amp;quot;here.&amp;quot;) would be output via the call&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  let $input := doc(&amp;quot;mydoc.xml&amp;quot;)/tei:TEI/tei:text&lt;br /&gt;
  local:milestone-chunk($input//pb[@n=&amp;quot;4&amp;quot;], ($input//node())[last()], $input)&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you use this function to recurse over all the '''pb''' elements in a document, you will need to use a strategy like this when '''$ms1''' has no following '''pb''' element.&lt;br /&gt;
&lt;br /&gt;
The function will not gracefully handle invalid input, but will probably throw run-time errors. You should be sure that the parameters passed to it reflect actual milestone elements with a common ancestor.&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
declare function local:milestone-chunk(&lt;br /&gt;
  $ms1 as element(),&lt;br /&gt;
  $ms2 as element(),&lt;br /&gt;
  $node as node()*&lt;br /&gt;
) as node()*&lt;br /&gt;
{&lt;br /&gt;
  typeswitch ($node)&lt;br /&gt;
    case element() return&lt;br /&gt;
      if ($node is $ms1) then $node&lt;br /&gt;
      else if ( some $n in $node/descendant::* satisfies ($n is $ms1 or $n is $ms2) )&lt;br /&gt;
      then&lt;br /&gt;
        element { name($node) }&lt;br /&gt;
                { for $i in ( $node/node() | $node/@* )&lt;br /&gt;
                  return local:milestone-chunk($ms1, $ms2, $i) }&lt;br /&gt;
      else if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
    case attribute() return $node (: will never match attributes outside non-returned elements :)&lt;br /&gt;
    default return &lt;br /&gt;
      if ( $node &amp;gt;&amp;gt; $ms1 and $node &amp;lt;&amp;lt; $ms2 ) then $node&lt;br /&gt;
      else ()&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementation in eXist ==&lt;br /&gt;
This function is implemented in eXist DB ([http://demo.exist-db.org/exist/functions/util/get-fragment-between ] util:get-fragment-between) by Josef Willenborg, Max Planck Institute for the History of Science [mailto:jwillenborg@mpiwg-berlin.mpg.de jwillenborg@mpiwg-berlin.mpg.de]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&amp;lt;nowiki&amp;gt;&lt;br /&gt;
util:get-fragment-between($beginning-node as node()?, $ending-node as node()?, $make-fragment as xs:boolean?) xs:string&lt;br /&gt;
&lt;br /&gt;
Returns an xml fragment or a sequence of nodes between two elements (normally milestone elements). The $beginning-node represents the first node/milestone element, $ending-node, the second one. The third argument, $make-fragment, is a boolean value for the path completion. If it is set to true() the result sequence is wrapped into a parent element node. &lt;br /&gt;
&lt;br /&gt;
Example call of the function for getting the fragment between two TEI page break element nodes: &lt;br /&gt;
let $fragment := util:get-fragment-between(//pb[1], //pb[2], true())&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:XQuery]]&lt;/div&gt;</summary>
		<author><name>Joey</name></author>
		
	</entry>
</feed>