0

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 :)

1 Answers1

0

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="'&#xa;'" />

    <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.

zx485
  • 28,498
  • 28
  • 50
  • 59
  • It didn't work out. I just added your code into the XSLT Sheet, but it did not appear in the HTML-Document – CHRISTOPH HARTLEB Oct 27 '18 at 16:13
  • If I use the tag, the whole document appears in plain text. But I want to have the output styled as it is in the normal document. Do you know what I can change here? Maybe I could send you the documents? – CHRISTOPH HARTLEB Oct 27 '18 at 16:16
  • You could set the output `method="html"`. But the result will still be text and no HTML `list` like `
      ` or `
      ` or something like that. If you want an HTML result in an HTML document, I really need more information.
    – zx485 Oct 27 '18 at 18:01
  • Hey, sorry for very late reply, it worked out for me, thank you somuch for your help ;) – CHRISTOPH HARTLEB Dec 02 '18 at 18:43
  • Thanks for your appropriate reply and welcome to StackOverflow. – zx485 Dec 02 '18 at 21:23