Note that there are some explanatory texts on larger screens.

plurals
  1. POInclude a XML in XSLT and then apply a foreach
    primarykey
    data
    text
    <p>I have a website coded with XML+XSLT that outputs me a full HTML website. Now, to make the site more dinamic I want to split some parts of the document: the header, footer and sidebar. I was looking at Google and I found this solution:</p> <pre><code>&lt;xsl:param name="doc" select="document('menu.xml')"/&gt; &lt;xsl:template match="/"&gt; &lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;xsl:for-each select="$doc"&gt;&lt;xsl:apply-templates/&gt;&lt;/xsl:for-each&gt;&lt;/body&gt;&lt;/html&gt; &lt;/xsl:template&gt; </code></pre> <p>I was trying to apply it and I can get it working. This is the way I am using:</p> <p>I changed the route to "../menu.xml" becasuse the xsl is inside a folder, this works well.</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:param name="menu" select="document('../menu.xml')"/&gt; &lt;xsl:template match="/"&gt; </code></pre> <p>more valid and working code and then:</p> <pre><code>&lt;ul class="menu_top"&gt; &lt;xsl:for-each select="$menu"&gt; &lt;li&gt; &lt;a&gt; &lt;xsl:attribute name="href"&gt; #&lt;xsl:value-of select="link" /&gt; &lt;/xsl:attribute&gt; &lt;xsl:value-of select="name"/&gt; &lt;/a&gt; &lt;/li&gt; &lt;/xsl:for-each&gt; &lt;/ul&gt; &lt;xsl:for-each select="$menu"&gt; &lt;div class="submenu"&gt; &lt;xsl:attribute name="id"&gt; &lt;xsl:value-of select="link" /&gt; &lt;/xsl:attribute&gt; &lt;ul&gt; &lt;xsl:for-each select="child"&gt; &lt;li&gt; &lt;a&gt; &lt;xsl:attribute name="href"&gt; &lt;xsl:value-of select="link" /&gt; &lt;/xsl:attribute&gt; &lt;xsl:value-of select="name"/&gt; &lt;/a&gt; &lt;/li&gt; &lt;/xsl:for-each&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/xsl:for-each&gt; </code></pre> <p>Finally my menu.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;menu&gt; &lt;category&gt; &lt;name&gt;First&lt;/name&gt; &lt;link&gt;menu-1&lt;/link&gt; &lt;child&gt; &lt;name&gt;Child 1&lt;/name&gt; &lt;link&gt;#&lt;/link&gt; &lt;/child&gt; &lt;child&gt; &lt;name&gt;Child 2&lt;/name&gt; &lt;link&gt;#&lt;/link&gt; &lt;/child&gt; &lt;/category&gt; &lt;/menu&gt; </code></pre> <p>I've more categories entries but I simplified it.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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. 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