Copied to clipboard

Flag this post as spam?

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


  • Sajid Riaz 142 posts 165 karma points
    Dec 12, 2010 @ 16:01
    Sajid Riaz
    0

    setting div id using xslt

    Hi ,

    I'm trying to set the id of a div as follows

     <div id=<umbraco:Macro Alias="SetContentID" runat="server"></umbraco:Macro>>
      

    this should render as follows <div id="default">

    but I dont know how to get the double quotes

     

    thanks

  • Sebastian Dammark 581 posts 1385 karma points
    Dec 12, 2010 @ 16:13
    Sebastian Dammark
    0

     

     

    <div>

    <xsl:attribute name="id">

    <umbraco:Macro Alias="SetContentID" runat="server" />

    </xsl:attribute>

    </div>

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 12, 2010 @ 16:43
    Kim Andersen
    1

    Hi Sajid

    If you want to create the div-element in your template, and then use a macro to insert the id attribute, you should be able to do it like this:

    In your template:

    <div <umbraco:Macro Alias="SetContentID" runat="server"></umbraco:Macro>>

    Then in your SetContentID xslt-file you should return something like this:

    id="default"

    You could create some different scenarios in your xslt-file using eg. a <xsl:choose> to determine what the id should be. Something like this:

    <xsl:choose>
    <xsl:when test="something here">id="alternativeID"</xsl:when>
    <xsl:otherwise>id="default"</xsl:otherwise>
    </xsl:choose>

    /Kim A

  • Sajid Riaz 142 posts 165 karma points
    Dec 12, 2010 @ 17:04
    Sajid Riaz
    0

     Thanks Guys,

    Kim your method works good.

    heres my xslt:

    <?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="/">
      <xsl:value-of select="$currentPage/backgroundImageID"/>
    </xsl:template>
    </xsl:stylesheet>

    here's how i used in html:

    <div id="<umbraco:Macro Alias='SetContentID' runat='server'></umbraco:Macro>">

     

    I set backgroundImageID the on the doc type.

    many thanks guys

    >sajid

     

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 12, 2010 @ 17:53
    Kim Andersen
    0

    Good to hear that you got i solved Sajid.

    But if your only want to output a textstring from the backoffice on the current page, you don't have to go through all the work of creating a XSLT-file/macro first. Then you can just do like this:

    <div id="<umbraco:Item field='backgroundImageID' runat='server'></umbraco:Item>">

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft