Copied to clipboard

Flag this post as spam?

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


  • Teena 44 posts 64 karma points
    Sep 26, 2010 @ 02:42
    Teena
    0

    changed special character in node name

    On my test page, , I am using the following xlst (below) to out put the footer menu and to  insert unique classes so they can be styled to match the design specified.  Unfortunately, one of the nodes was named Products/Services and the slash kills the css.  I changed the name of the node to ProductsService to make my css work but is there a way to write just the first word in the Node name as class instead of the whole thing?  

    Thanks in advance!

     

    <?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="/">

    <!-- start writing XSLT -->
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(data [@alias='displayInFooter']) = '1']">

    <xsl:if test="./node/@id !=''">
    <div class="footer-mod"><xsl:attribute name="id"><xsl:value-of select="@nodeName"/></xsl:attribute>
            <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="@nodeName"/></xsl:attribute><xsl:value-of select="@nodeName"/></a></h3>

            <ul>
                    <xsl:for-each select="./node [string(data [@alias='umbracoNaviHide']) != '1']">
                            <li>
                                    <a href="{umbraco.library:NiceUrl(@id)}">
                                            <xsl:value-of select="@nodeName"/>
                                    </a>
                            </li>
                    </xsl:for-each>
            </ul></div>
    </xsl:if>
    </xsl:for-each>



    </xsl:template>
  • Rich Green 2246 posts 4008 karma points
    Sep 26, 2010 @ 10:11
    Rich Green
    0

    Hi,

    You could just strip out your special character

    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="umbraco.library:Replace(@nodeName, '/', '')"/></xsl:attribute></a></h3> >  

    Best of luck

    Rich

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 26, 2010 @ 10:31
    Dirk De Grave
    0

    Teena,

    Although Rich's suggestion will work, I still think it's a bad design to "synchronize" the css class name with the name of the node (or part of the node name), you'll always run into issues as you've just experienced, but also when new nodes are created that need to have chars replaced (umbracoSettings.config has the list of replaced chars), but also when renaming nodes. As you'll base the css class name on the node name, you'll have to do an intervention anytime this changes.

    I'd look into adding the css class name as a property on the node and hide that property using this project.

     

    Hope this helps.

    Regards,

    /Dirk

  • Rich Green 2246 posts 4008 karma points
    Sep 26, 2010 @ 10:46
    Rich Green
    0

    Agree that Dirks solution is much better in the long run.

    Rich

  • Teena 44 posts 64 karma points
    Sep 26, 2010 @ 16:53
    Teena
    0

    I don't really follow the second suggestion and there is no time left in the project so I'm attempting to strip out the special character as per Rich's suggest. 

    Inserting:

    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="umbraco.library:Replace(@nodeName, '/', '')"/></xsl:attribute></a></h3> >

    Resulted in h3 tags containing ">" across the board.  Tried removing the final ">", this resulted in empty h3 tags.

    <h3 style="visibility: visible;"><a class="ProductsServices" href="/products-and-services.aspx"></a></h3>

    Edited to include  <xsl:value-of select="@nodeName"/> where I expect to display the visible link:

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="umbraco.library:Replace(@nodeName, '/', '')"/></xsl:attribute><xsl:value-of select="@nodeName"/></a></h3>

    This returns a visible link of "ProductServices" :

    <h3 style="visibility: visible;"><a class="ProductsServices" href="/products-and-services.aspx" style="display: inline-block;">ProductsServices</a></h3>

    Kinda back where I started the long way around.  I guess I need to add the slash back in for link display?

    Any suggestions appreciated.

  • Rich Green 2246 posts 4008 karma points
    Sep 26, 2010 @ 17:11
    Rich Green
    0

    Teena,

    Your last entry doesn't make sense

    <a class="ProductsServices" href="/products-and-services.aspx" style="display: inline-block;">ProductsServices</a>

    This must mean your node is called "Products and Services". Also there's no mention style="display" etc in your XSLT.

    This code should work (exactly the same as your code posted above)

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="umbraco.library:Replace(@nodeName, '/', '')"/></xsl:attribute><xsl:value-of select="@nodeName"/></a></h3>

    Maybe post the whole XSLT you are trying.

    Dirks suggestion makes perfect sense, so not sure what's hard to follow.

    Basically it's saying, add a attribute to your DocType named "cssclass" then in your XSLT

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="data [@alias='cssclass']"/></xsl:attribute><xsl:value-of select="@nodeName"/></a></h3>

    Then in your Product & Services node just fill in the exact name you want for your css class.

    Rich

  • Teena 44 posts 64 karma points
    Sep 26, 2010 @ 19:33
    Teena
    0

    Here's the xlst:

    <?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="/">

    <!-- start writing XSLT -->
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=1]/node [string(data [@alias='displayInFooter']) = '1']">

    <xsl:if test="./node/@id !=''">
    <div class="footer-mod"><xsl:attribute name="id"><xsl:value-of select="@nodeName"/></xsl:attribute>

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="umbraco.library:Replace(@nodeName, '/', '')"/></xsl:attribute><xsl:value-of select="@nodeName"/></a></h3>



    <ul>
    <xsl:for-each select="./node [string(data [@alias='umbracoNaviHide']) != '1']">
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </xsl:for-each>
    </ul></div>
    </xsl:if>
    </xsl:for-each>



    </xsl:template>

    </xsl:stylesheet>

    Here's the code it generates at in the footer at Products/Services:

    <h3 style="visibility: visible;"><a class="ProductsServices" href="/products-and-services.aspx" style="display: inline-block;">ProductsServices</a></h3>

    My content page properties:

  • Rich Green 2246 posts 4008 karma points
    Sep 26, 2010 @ 19:41
    Rich Green
    0

    Hi Teena,

    This should work for you

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:attribute name="class"><xsl:value-of select="@nodeName"/></xsl:attribute><xsl:value-of select="data [@alias='umbracoUrlName']"/></a></h3>

    Although this should work it will become a problem if your user changes the name of the node.

    Rich

  • Teena 44 posts 64 karma points
    Sep 26, 2010 @ 22:02
    Teena
    0

    Thanks Rich,

     

    This worked wonderfully, just what I was looking for. 

     

    Thanks for your help!

Please Sign in or register to post replies

Write your reply to:

Draft