Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use one template to create the result document structure e.g.</p> <pre><code> &lt;xsl:template match="/"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;XML Week 7&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;xsl:apply-templates/&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; </code></pre> <p>then write further templates to create the content e.g.</p> <pre><code>&lt;xsl:template match="lecturers"&gt; &lt;h1&gt;Week 7: Lecturers file turned to XSL:Template&lt;/h1&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;th&gt;&lt;b&gt;Title&lt;/b&gt;&lt;/th&gt; &lt;th&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/th&gt; &lt;th&gt;&lt;b&gt;Teaching&lt;/b&gt;&lt;/th&gt; &lt;th&gt;&lt;b&gt;Research&lt;/b&gt;&lt;/th&gt; &lt;/tr&gt; &lt;xsl:apply-templates/&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;xsl:template match="lecturer"&gt; &lt;tr&gt; &lt;td&gt;&lt;xsl:value-of select="name/title" /&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="name/first" /&gt;&lt;xsl:text&gt;&amp;#x20;&lt;/xsl:text&gt;&lt;xsl:value-of select="name/last" /&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="teaching/course" /&gt; and &lt;xsl:value-of select="(teaching/course)[2]" /&gt;&lt;/td&gt; &lt;td&gt;&lt;xsl:value-of select="lecturers/lecturer/research" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:template&gt; </code></pre> <p>As you see, the templates do an <code>apply-templates</code> to keep up the processing.</p> <p>[edit] In response to your comment, if you want to use more templates for the different child or descendant elements of the <code>lecturer</code> element you can use</p> <pre><code>&lt;xsl:template match="lecturer"&gt; &lt;tr&gt; &lt;xsl:apply-templates/&gt; &lt;/tr&gt; &lt;/xsl:template&gt; </code></pre> <p>and then write templates for the elements e.g.</p> <pre><code>&lt;xsl:template match="name/title | research"&gt; &lt;td&gt; &lt;xsl:value-of select="."/&gt; &lt;/td&gt; &lt;/xsl:template&gt; &lt;xsl:template match="name/first"&gt; &lt;td&gt; &lt;xsl:value-of select="concat(., ' ', ../last)"/&gt; &lt;/td&gt; &lt;/xsl:template&gt; &lt;!-- don't output name/last as the name/first template already does --&gt; &lt;xsl:template match="name/last"/&gt; &lt;xsl:template match="teaching"&gt; &lt;xsl:apply-templates select="course"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="course"&gt; &lt;xsl:if test="position() &gt; 1"&gt;&lt;xsl:text&gt; and &lt;/xsl:text&gt;&lt;/xsl:if&gt; &lt;xsl:value-of select="."/&gt; &lt;/xsl:template&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload