i wanted to ask you for help. I am totally new to XSLT and i wanted to know if someone can show me the right XSLT stylesheet for the following TEI-snipet:
<div>
<head>Weitere Aufzählungen</head>
<list rend="numbered">
<item n="1">A</item>
<item n="2">B</item>
<item n="3">C<list rend="numbered">
<item n="3.1">a</item>
<item n="3.2">b</item>
</list>
</item>
</list>
</div>
The Output should look like that in the HTML-Document:
1. A
2. B
3. C
3.1 a
3.2 b
Thank you so much for helping me :)
If you want a text output, the following stylesheet with <xsl:output method="text" />
will do. It distinguishes the level of indentation by counting the item ancestor nodes and adds an extra .
on level 0.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" />
<xsl:variable name="newLine" select="'
'" />
<xsl:template match="text()" />
<xsl:template match="/div/list">
<xsl:apply-templates select="item" />
</xsl:template>
<xsl:template match="item">
<xsl:for-each select="ancestor::item"><xsl:text> </xsl:text></xsl:for-each>
<xsl:value-of select="@n" />
<xsl:if test="not(ancestor::item)"><xsl:text>.</xsl:text></xsl:if>
<xsl:value-of select="concat(' ',text(),$newLine)" />
<xsl:apply-templates select="list" />
</xsl:template>
</xsl:stylesheet>
Output is:
1. A
2. B
3. C
3.1 a
3.2 b
BTW you may need to add an appropriate namespace declaration for the TEI namespace to the xsl:stylesheet
element.