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>
I'm not 100% sure I know exactly what output you want (it is generally a good idea to show your desired output rather than relying on a description of what you're trying to do), but it looks like you want to group the
descchild elements starting with eachdate, and within that group you want to create a distincteventfor everyplaceNamewhich would then contain theplaceNameand also thenote? Possibly also thedate?Anyway, I hope this suggestion gets you closer to what you want:
Result: