Copied to clipboard

Flag this post as spam?

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


  • Evan 344 posts 99 karma points
    Jul 03, 2009 @ 17:52
    Evan
    0

    Need to strip the spaces from @nodeName for my li ID...

    For styling purposes I would like to add the nodename as the id for each li in my navigation.  I have it working except I need to strip the spaces so that I can use css for styling.  How can I strip the spaces?

    <code>

    <?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"
        exclude-result-prefixes="msxml umbraco.library">


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

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <ul id="navi">

                <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::node [@level=1]" />
               
                <li>
                  <!--
                      Add the ID to equal the nodeName for styling purposes
                  -->
                  <xsl:attribute name="ID">
                    <xsl:value-of select="$rootNode/@nodeName" />
                  </xsl:attribute>
                    <!--
                        Add the class selected if the root node ID matches our
                        current node ID in the for each loop
                     -->
                    <xsl:if test="$rootNode/@id = $currentPage/@id">
                        <xsl:attribute name="class">
                            <xsl:text>
                                selected
                            </xsl:text>
                        </xsl:attribute>
      
                    </xsl:if>
                   
                    <a href="{umbraco.library:NiceUrl($rootNode/@id)}">
                        <xsl:value-of select="$rootNode/@nodeName" />
                    </a>
                </li>
               
                <xsl:for-each select="$currentPage/ancestor-or-self::node/node [@level = 2 and string(data[@alias='umbracoNaviHide']) != '1']">
                    <li>
                    <!--
                      Add the ID to equal the nodeName for styling purposes
                    -->
                      <xsl:attribute name="ID">
                        <xsl:value-of select="@nodeName" />
                      </xsl:attribute>
                      <!--
                        Add the class selected if the currentpage or parent nodes (up the tree to the root)
                        ID matches our current node ID in the for each loop
                      -->
                        <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                            <xsl:attribute name="class">
                                <xsl:text>
                                    selected
                                </xsl:text>
                            </xsl:attribute>
                        </xsl:if>
                       
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="@nodeName" />
                        </a>
                    </li>
                </xsl:for-each>
            </ul>

        </xsl:template>

    </xsl:stylesheet>

    </code>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 03, 2009 @ 18:49
    Jan Skovgaard
    101

    I am not quite sure if it will work.

    But have you tried using the replace function to do something like?

    <xsl:value-of select="umbraco.library:Replace('yourstring', ' ', '-')"/>
  • Evan 344 posts 99 karma points
    Jul 03, 2009 @ 19:05
    Evan
    0

    Works like a charm, made my spaces dashes, perfect for styling.  Genius !!!

Please Sign in or register to post replies

Write your reply to:

Draft