I have an XML that sort of looks like this:
<desc year="1879">
<date from="1879-08-30" to="1879-08-30"/>
<placeName>New York</placeName>
<placeName>New Jersey</placeName>
<note>visiting my grandma</note>
<date from="1879-10-30" to="1879-11-01"/>
<placeName>Berlin</placeName>
<note>with my mother</note>
<placeName>Hamburg</placeName>
</desc>
I want to transfer the desc Elements to event Elements for each placeName. This works out, but either every note is transferred to every event and not just the one from placeName before it or no note elements at all.
This is my current code:
<xsl:template match="//tei:desc">
<xsl:variable name="note-content">
<xsl:for-each select="//tei:placeName">
<xsl:if test="following-sibling::tei:note[1]">
<xsl:element name="note" namespace="http://www.tei-c.org/ns/1.0">
<xsl:value-of select="following-sibling::tei:note[1]"/>
</xsl:element>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:for-each-group select="*" group-starting-with="tei:date">
<!-- other specifications -->
<xsl:for-each select="current-group()[name()='placeName']">
<xsl:element name="event" namespace="http://www.tei-c.org/ns/1.0">
<!-- other specifications -->
<xsl:element name="desc" namespace="http://www.tei-c.org/ns/1.0">
<xsl:element name="placeName" namespace="http://www.tei-c.org/ns/1.0">
<xsl:attribute name="ref"/>
<xsl:value-of select="."/>
</xsl:element>
</xsl:element>
<xsl:if test="$note-content !=''">
<xsl:element name="note" namespace="http://www.tei-c.org/ns/1.0">
<xsl:value-of select="$note-content"/>
</xsl:element>
</xsl:if>
</xsl:element>
</xsl:for-each>
</xsl:for-each-group>
</xsl:template>