Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jonas Berling 30 posts 50 karma points
    Dec 02, 2011 @ 23:04
    Jonas Berling
    0

    Mixing XSLT and HTML tags

    I'm writing an XSLT macro that should loop through a number of nodes and for each node display some data (description text and a picture). I want the list to be in a two-column table so I started out with the 'Table prototype' template. The problem is that I can't get the mix of XSLT tags and HTML tags to play along.

    The code below can not be saved as it complains about unmatched tags and when I tried to replace every HTML tag, e.g. <td> with &lt;td> the code saves and renders fine when I do 'Visualize XSLT' but running the macro in a real page renders the HTML tags (&lt;td>) intead of interpreting them.

    What would be the correct way of mixing XSLT and HTML tags?

    I'm running v4.5.2.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <table border="0" cellspacing="0" cellpadding="5">
    <tr>
    <xsl:for-each select="$currentPage/node()/bild">
      <xsl:choose>
       <xsl:when test="position() mod 3 = 0">
        </tr>
        <tr>
       </xsl:when>
      </xsl:choose>
      <td>
      <B><xsl:value-of select="./../rubrik"/></B><br/>
      <xsl:variable name="media" select="umbraco.library:GetMedia(., 0)" />     
      <xsl:if test="$media">         
        <a href=&quot;<xsl:value-of select="./../tillverkarensURL"/>&quot; border=&quot;1&quot;><img src="{$media/umbracoFile}" alt="{$media/altText}" width="318" height="196"/>&lt;/a>
      </xsl:if>
     
      </td>
    </xsl:for-each>
    </table>

    </xsl:template>

    </xsl:stylesheet>

     

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Dec 02, 2011 @ 23:28
    Chriztian Steinmeier
    1

    Hi Jonas,

    One thing you need to know right away is that an XSLT file must be a wellformed XML file, so you can't conditionally output e.g. a close tag, like you're trying to.

    You need to think differently about the output you're trying to generate - I've answered a couple of similar posts - one that fits your desired output would be this one, which explains how to go about generating table rows.

    Hope it helps - otherwise, let us know!

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft