das folgende XML Gegeben:XPath1 - Auswahl Geschwister
<p class='sectiontitle'>Examples</p>
<p class='paragraphtitle'>Example1</p>
<p>That's some text.</p>
<p>That's some text again.</p>
<p class='paragraphtitle'>Example2</p>
<p>That's some other text.</p>
<p>That's some other text again.</p>
<!-- potentially add more paragraphtitles -->
<p class='sectiontitle'>New title</p>
<p>Some non-needed text.</p>
Ich möchte eine Vorlage laufen auf jedem Absatz Abschnitt zu arbeiten, wo ich den Titel und seine folgenden Inhalt in einigen neuen Tags wickeln.
Also habe ich eine XSLT1.1/Xpath1 Datei, die alle p [@ Klasse = 'Absatztitel'] und innerhalb der Vorlage für diese, möchte ich ihre folgenden Geschwister bis zum nächsten Untertitel oder Abschnitt Titel wählen.
<xsl:template match="p[@class='paragraphtitle']" mode="create-example-block">
<example>
<title>
<xsl:value-of select="." />
</title>
<xsl:apply-templates
select="//p[@class='sectiontitle' or @class='paragraphtitle']/preceding-sibling::*[preceding-sibling::p[@class='paragraphtitle'][1] = text() and not(self::p[@class='sectiontitle' or @class='paragraphtitle'] or not(self::*[following-sibling::p[@class='sectiontitle']]))]" />
</example>
</xsl:template>
, die nicht die erwartete Ausgabe produziert, in diesem Fall erwarte ich:
<example>
<title>Example1</title>
<p>That's some text.</p>
<p>That's some text again.</p>
</example>
<example>
<title>Example2</title>
<p>That's some other text.</p>
<p>That's some other text again.</p>
</example>
Kann mir jemand einen Tipp geben?
Siehe http : //stackoverflow.com/a/36781226/252228 zum Beispiel oder ähnliche Fragen und Antworten. –