Я новичок в XSLT.Так что, возможно, мой вопрос не очищен, у меня есть файл ниже XML для индекса и я хочу преобразовать XML как ниже ожидаемого вывода.
<root>
<para>absgx</para>
<para>– abcd asjdsaj AD I.</para>
<para>– abcd asjdsaj AD II.12.5, I.abc.</para>
<para>– abcd asjdsaj AD Ibis.aass.</para>
<para>absgx</para>
<para>absgx</para>
<para>– abcd asjdsaj AD II.</para>
<para>° abcd asjdsaj AD I.a</para>
<para>° abcd asjdsaj AD I.b</para>
<para>– abcd asjdsaj AD II.</para>
<para>– abcd asjdsaj AD III.</para>
<para>absgx</para>
</root>
ожидаемый вывод:
<root>
<index>
<title/>
<indexdiv>
<title/>
<indexentry>
<primaryie>absgx</primaryie>
<secondaryie>– abcd asjdsaj AD <pg>I.</pg></secondaryie>
<secondaryie>– abcd asjdsaj AD <pg>II.12.5</pg></secondaryie>
<secondaryie>– abcd asjdsaj AD <pg>Ibis.aass.</pg></secondaryie>
</indexentry>
<indexentry>
<primaryie>absgx</primaryie>
</indexentry>
<indexentry>
<primaryie>absgx</primaryie>
<secondaryie>– abcd asjdsaj AD <pg>II.</pg></secondaryie>
<tertryie level="1">° abcd asjdsaj AD <pg>I.a</pg></tertryie>
<tertryie level="1">° abcd asjdsaj AD <pg>I.b</pg></tertryie>
<secondaryie>– abcd asjdsaj AD <pg>II.</pg></secondaryie>
<secondaryie>– abcd asjdsaj AD <pg>III.</pg></secondaryie>
</indexentry>
<indexentry>
<primaryie>absgx</primaryie>
</indexentry>
</indexdiv>
</index>
</root>
Почти у меня естьсделано, но я не могу сгенерировать "indexentry" с каждым элементом "primaryie".Ниже мой XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml"/>
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="para">
<xsl:choose>
<xsl:when test=".[starts-with(.,'–')]">
<xsl:element name="secondaryie">
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:when test=".[starts-with(., '°')]">
<xsl:element name="tertryie">
<xsl:attribute name="level" select="1"></xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="primaryie">
<xsl:apply-templates/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="I.*">
<xsl:matching-substring>
<xsl:element name="pg">
<xsl:value-of select="."/>
</xsl:element>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="current()"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
Поэтому, пожалуйста, предложите, как мы заполняем "indexentry".