Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:47:11+00:00 2026-06-18T10:47:11+00:00

Hi I am a complete beginner with xslt and have just started using it

  • 0

Hi I am a complete beginner with xslt and have just started using it as I am building a site with Umbraco. I was wondering if there was any way of creating functions within xslt so I didn’t have to repeat the same thing over. I have had a look at a few sites but don’t really understand it

My code is:

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

<xsl:variable name="items" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 1]/* [@isDoc and string(umbracoNaviHide) != '1']"/>

<!-- The fun starts here -->

<xsl:if test="count($items) &gt; 0">
<ul id="SubNav" class="level{@level}">
  <xsl:for-each select="$items">
  <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName"/>
    </a>
    <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
        <ul class="level{@level}">
        <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '1']">
          <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>
            </a>
            <xsl:if test="count(./child::*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
                <ul class="level{@level}">
                <xsl:for-each select="./child::*[@isDoc and string(umbracoNaviHide) != '1']">
                  <li>
                    <a href="{umbraco.library:NiceUrl(@id)}">
                      <xsl:value-of select="@nodeName"/>
                    </a>
                  </li>
                </xsl:for-each>
                </ul>
            </xsl:if>
          </li>
        </xsl:for-each>
        </ul>
    </xsl:if>
  </li>
  </xsl:for-each>
</ul>
</xsl:if>

</xsl:template>

</xsl:stylesheet>

As you can see foreach node I am reusing the same code to list the children so I was wondering if I could pull this out into a function so I wouldn’t have to nest the same code for each level of children I need

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:47:13+00:00Added an answer on June 18, 2026 at 10:47 am

    The idea in XSLT is to work with templates that match certain nodes in your XML structure. You can even apply the same exact template with different processing instructions using "modes".

    I do not know your XML structure but I assume that would be the way to go. Searching in stackoverflow provides information too: https://stackoverflow.com/questions/tagged/templates+xslt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I state that I am a complete beginner to LDAP. I have to let
First off, I'm a complete beginner at C++. I'm coding something using an API,
I am a complete beginner in SQL. I am using a program that queries
I'm a complete beginner in WPF and have an app that uses StoryBoard to
I'm a complete beginner to any sort of decrypting. I wrote a class that
I'm a complete beginner in JS, so pls have patience :) my.hello = function
I'm a complete beginner with jQuery and I have this bit of script here
I have Xcode 4.2 and I am a complete beginner. One of my files
I am a complete beginner in C programming, so please have some patience with
Ok so I am a complete beginner and have managed to put together a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.