Note that there are some explanatory texts on larger screens.

plurals
  1. POOpening and closing HTML tag in XSLT
    text
    copied!<p>I have this XML: </p> <pre><code> &lt;XmlTreff IsSub="false" Start="false" Stop="false"&gt; &lt;Id&gt;Id0&lt;/Id&gt; &lt;Tittel&gt;Title0&lt;/Tittel&gt; &lt;/XmlTreff&gt; &lt;XmlTreff IsSub="false" Start="false" Stop="false"&gt; &lt;Id&gt;Id1&lt;/Id&gt; &lt;Tittel&gt;Title1&lt;/Tittel&gt; &lt;/XmlTreff&gt; &lt;XmlTreff IsSub="true" Start="true" Stop="false"&gt; &lt;Id&gt;Id2&lt;/Id&gt; &lt;Tittel&gt;Title2&lt;/Tittel&gt; &lt;/XmlTreff&gt; &lt;XmlTreff IsSub="true" Start="false" Stop="false"&gt; &lt;Id&gt;Id3&lt;/Id&gt; &lt;Tittel&gt;Title3&lt;/Tittel&gt; &lt;/XmlTreff&gt; &lt;XmlTreff IsSub="true" Start="false" Stop="true"&gt; &lt;Id&gt;Id4&lt;/Id&gt; &lt;Tittel&gt;Title4&lt;/Tittel&gt; &lt;/XmlTreff&gt; &lt;XmlTreff IsSub="false" Start="false" Stop="false"&gt; &lt;Id&gt;Id5&lt;/Id&gt; &lt;Tittel&gt;Title5&lt;/Tittel&gt; &lt;/XmlTreff&gt; </code></pre> <p>This XML is transformed with XSLT and should produce this HTML</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div&gt; &lt;div&gt; &lt;a href="doesntmatter"&gt;Title0&lt;/a&gt; &lt;/div&gt; &lt;div&gt; &lt;a href="doesntmatter"&gt;Title1&lt;/a&gt; &lt;/div&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="doesntmatter"&gt;Title2&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="doesntmatter"&gt;Title3&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="doesntmatter"&gt;Title4&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;div&gt; &lt;a href="doesntmatter"&gt;Title5&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The thought was that the attributes Start, Stop, and IsSub controls the opening and closing of the tags.</p> <p>Currently i have this XSLT:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/XmlSokeResultat/Treff"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="no" xml:lang="no"&gt; &lt;body&gt; &lt;xsl:for-each select="XmlTreff"&gt; &lt;div class="XmlTreffinfo"&gt; &lt;xsl:if test="@IsSub = 'false'"&gt; &lt;div&gt; &lt;div&gt; &lt;xsl:element name="a"&gt; &lt;xsl:value-of select="Tittel"/&gt; &lt;/xsl:element&gt; &lt;/div&gt; &lt;/div&gt; &lt;/xsl:if&gt; &lt;xsl:if test="@Start = 'true'"&gt; &lt;div&gt; &lt;ul&gt; &lt;/xsl:if&gt; &lt;xsl:if test="@IsSub = 'true'"&gt; &lt;ul&gt; &lt;li&gt; &lt;a&gt; &lt;xsl:value-of select="."/&gt; &lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/xsl:if&gt; &lt;xsl:if test="@Stop = 'true'"&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/xsl:if&gt; &lt;/div&gt; &lt;/xsl:for-each&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>The problem is that having opening and closing tags in a syntactical wrong place is not allowed. Do you know how to solve this? (See inside the ifs where the starting div and ul are placed at different place than the closing tags)</p> <p>EDIT: I can add and remove attributes to the XML, but the element structure must be like this?</p> <p>EDIT2: I have tried to render out the HTML tags using concat and value-of</p> <pre><code> &lt;xsl:value-of disable-output-escaping="yes" select="concat('&amp;lt;', '/ul', '&amp;gt;')" /&gt; &lt;xsl:value-of disable-output-escaping="yes" select="concat('&amp;lt;', '/div', '&amp;gt;')" /&gt; </code></pre> <p>Interestingly, IE10 can handle this and but Firefox is not able to render it out correctly.</p>
 

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