Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplaying all contents between xml milestones
    primarykey
    data
    text
    <p>I have an xml document that looks like this: </p> <pre><code>&lt;div&gt; &lt;p&gt;Hello my name is Bob &lt;cb ed="#R" n="1/&gt;and I live in a house&lt;/p&gt; &lt;p&gt;My name is Susan.&lt;/p&gt; &lt;p&gt;Where are you from?&lt;/p&gt; &lt;p&gt;I am from &lt;cb ed="#R" n="2/&gt;Chicago, Illinois&lt;/p&gt; &lt;p&gt;I also live in Chicago&lt;/p&gt; &lt;p&gt;But I wish I &lt;cb ed="#R" n="3"/&gt;lived in New York&lt;/p&gt; &lt;/div&gt; </code></pre> <p>and so on ...</p> <p>I basically want to transform it so tags surround all the stuff between the first and the second and so on ... but I would also like to preserve the existing paragraphs within the newly created divs. This means also creating a <p> tag around the text node that is the immediate following sibling to the element.</p> <p>I want the result to look something like: </p> <pre><code> &lt;div id="1"&gt; &lt;p&gt;and I live in a house&lt;/p&gt; &lt;p&gt;My name is Susan.&lt;/p&gt; &lt;p&gt;Where are you from?&lt;/p&gt; &lt;p&gt;I am from&lt;/p&gt; &lt;/div&gt; &lt;div id="2"&gt; &lt;p&gt;Chicago, Illinois&lt;/p&gt; &lt;p&gt;I also live in Chicago&lt;/p&gt; &lt;p&gt;But I wish I&lt;/p&gt; &lt;/div&gt; &lt;div id="3"&gt; &lt;p&gt;lived in New York&lt;/p&gt; &lt;/div&gt; </code></pre> <p>This is proving rather difficult. I wonder if someone can help me get on the right track - or point me to an example of a similar kind of transformation.</p> <p>Here's what I have so far:</p> <pre><code> &lt;xsl:template match="tei:p"&gt; &lt;xsl:choose&gt; &lt;xsl:when test="./tei:cb[@ed='#R']"&gt; &lt;xsl:variable name="number" select="./tei:cb[@ed='#R']/@n"/&gt; &lt;div id="{$number}"&gt; &lt;span&gt;test&lt;/span&gt; &lt;xsl:for-each select="./tei:cb[@ed='#R']/following::p[preceding::tei:cb[@ed='#R']]"&gt; &lt;p&gt;&lt;xsl:value-of select="."/&gt;&lt;/p&gt; &lt;/xsl:for-each&gt; &lt;/div&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p>So far the only result is: </p> <pre><code> &lt;div id="1rb"&gt;&lt;span&gt;test&lt;/span&gt;&lt;/div&gt; &lt;div id="1va"&gt;&lt;span&gt;test&lt;/span&gt;&lt;/div&gt; &lt;div id="1vb"&gt;&lt;span&gt;test&lt;/span&gt;&lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload