Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Apr 02, 2013 @ 11:45
    Martin
    0

    XSLT Validation - Opening Tag Only

    Hi, 

    Im looking to apply a class to a div by using a macro, with a dropdown list datatype.

    The div that i want to apply a class to looks like this.

       <div class="content">
     <umbraco:Macro Alias="Config-SelectProductClass" runat="server" />
     <asp:ContentPlaceHolder Id="Content" runat="server" />
    </div> 

    I have tried to output the first part of the <div class="content"> within the macro, but i am getting a validation error for not closing the div.

    Any ideas on how i can output the first part of the div within the macro? or is this even a good idea to do it this way?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 02, 2013 @ 11:58
    Chriztian Steinmeier
    0

    Hi Martin,

    You cant do that in a nice way - you *can* set your XSLT to output "text" only, e.g. like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="text" indent="no" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <xsl:if test="canhaz:WorldDomination() = true()"><![CDATA[ class="hacks away"]]></xsl:if>
        </xsl:template>
    
    </xsl:stylesheet>

    (Please not that you need to put your own condition in the test="" attribute — mine will definitely fail :-)

    /Chriztian 

  • Martin 278 posts 662 karma points
    Apr 02, 2013 @ 15:39
    Martin
    0

    Hi Criztian, 

    Thanks for the reply, although im looking to apply the class on the content div, using the datatype with a dropdown.

    Could the asp content placeholder be outputted through the CDATA method you posted?

    Is there any issue that would arise from that?

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 02, 2013 @ 15:48
    Chriztian Steinmeier
    100

    Hi Martin,

    It won't do any good to output the Content control tags from the macro - at that point they're just text rendered to the page, so they wouldn't be picked up by the server process... (I would be very surprised if that worked).

    Is the datatype in the Macro or is it on the Document Type? If it's on the document you can use inline XSLT (or a simple Item control) to output the value... ?

    /Chriztian

     

  • Martin 278 posts 662 karma points
    Apr 02, 2013 @ 16:02
    Martin
    0

     

    Hi Chriztian

    I created a simple datatype using the dropdown list property editor. It has a 3 values that represent the class values.

    Ive used the datatype inside document type. 

    I was tryng to apply the class using a macro with a simple attribute call.

     

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

    <xsl:param name="currentPage"/>

    <xsl:variable name="class" select="$currentPage/ancestor-or-self::*/selectClass"/>

    <xsl:template match="/">

     

    <div class="content">

    <xsl:if test="$class !=''">

    <xsl:attribute name="class">

    <xsl:value-of select="$class"/>

    </xsl:attribute>

    </xsl:if>

    </div>

    </xsl:template>

    * sorry the forum code styling has gone missing.

     

  • Martin 278 posts 662 karma points
    Apr 02, 2013 @ 16:07
    Martin
    0

    Thanks Chriztain. got it working using the inline method

Please Sign in or register to post replies

Write your reply to:

Draft