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 7968275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:03:04+00:00 2026-06-04T07:03:04+00:00

I am trying to loop through a node, which in itselt is not a

  • 0

I am trying to loop through a node, which in itselt is not a problem. I want to check to see if the selectedLetter matches the first letter of the node, which is working as intended (see code below). The difficulties arise in that I would like to present some alternative text if the conditional “” is not met at least once during the loop, along the lines of “Sorry, no documents begin with that letter”. I was thinking about setting a variable i.e. flag in the conditional and check later on if this variable has been set, but from what I have read here, the scope of the variable is restricted and only available within the loop? Can anyone offer any assistance?

Cheers,
Taff

<xsl:param name="selectedLetter" select="''"/>
<xsl:key name="docLetter" match="docs" use="substring(text()),1,1)"/>

                <xsl:for-each select="//ad-documents/item">

                    <xsl:sort select="documentName"/>
                    <xsl:variable name="firstLetter" select="upper-case(substring(documentName, 1, 1))"/>

                    <xsl:choose>

                        <xsl:when test="$firstLetter = $selectedLetter">

                            <div class="doc-date">
                                <xsl:if test="upload-date/day &lt; 10">0</xsl:if>
                                <xsl:value-of select="upload-date/day"/>
                                <xsl:text>.</xsl:text>
                                <xsl:if test="upload-date/month &lt; 10">0</xsl:if>
                                <xsl:value-of select="upload-date/month"/>
                                <xsl:text>.</xsl:text>
                                <xsl:value-of select="upload-date/year"/>
                            </div>

                            <div class="doc-link">
                                <a>
                                    <xsl:attribute name="href">
                                        <xsl:choose>
                                            <xsl:when test="isEditableFormDoc/box = 'true'">
                                                #
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:text>/img/ejbfile/</xsl:text>
                                                <xsl:value-of select="documents/document/@documentName"/>
                                                <xsl:text>?id=</xsl:text>
                                                <xsl:value-of select="documents/document/@src"/>
                                            </xsl:otherwise>
                                        </xsl:choose>      
                                    </xsl:attribute>
                                    <xsl:if test="isEditableFormDoc/box = 'true'">
                                        <xsl:attribute name="target">
                                            <xsl:text>_blank</xsl:text>
                                        </xsl:attribute>
                                    </xsl:if>
                                    <xsl:value-of select="documentName"/>
                                </a>
                            </div>

                            <div class="doc-short-desc">
                                <xsl:apply-templates select="document-short-desc" mode="format"/>
                            </div>

                            <!--<xsl:apply-templates select="//ad-documents/item" mode="filteredDocuments"/>-->
                        </xsl:when>
                    </xsl:choose>

              </xsl:for-each>

EDIT:

XML Example

<ad-documents name="ad-documents" label="Dokumente (limitiert auf 20 pro Seite)">
  <item description="Doc%203" id="1" timestamp="1328525592205">
    <documentName name="documentName" description="Doc%203">Doc 3</documentName>
    <optionalLetter name="optionalLetter" description="c">c</optionalLetter>
    <document-short-desc name="document-short-desc" description="">
      <p>yxf</p>
    </document-short-desc>
    <upload-date name="upload-date" description="">
      <day>24</day>
      <month>2</month>
      <year>2012</year>
    </upload-date>
    <isEditableFormDoc name="isEditableFormDoc" description="">
      <box/>
    </isEditableFormDoc>
    <documents name="documents" description=""/>
  </item>
  <item description="Doc%204" id="2" timestamp="1328525624889">
    <documentName name="documentName" description="Doc%204">Doc 4</documentName>
    <optionalLetter name="optionalLetter" description="z%2Ci%2Cg">z,i,g</optionalLetter>
    <document-short-desc name="document-short-desc" description="">
      <p>asff</p>
    </document-short-desc>
    <upload-date name="upload-date" description="">
      <day>25</day>
      <month>2</month>
      <year>2012</year>
    </upload-date>
    <isEditableFormDoc name="isEditableFormDoc" description="">
      <box/>
    </isEditableFormDoc>
    <documents name="documents" description=""/>
  </item>
  <item description="Doc%201" id="1" timestamp="1328523551639">
    <documentName name="documentName" description="Doc%201">Doc 1</documentName>
    <optionalLetter name="optionalLetter" description="b%2Cc">b,c</optionalLetter>
    <document-short-desc name="document-short-desc" description="">
      <p>Short Desc 1</p>
    </document-short-desc>
    <upload-date name="upload-date" description="">
      <day>9</day>
      <month>2</month>
      <year>2012</year>
    </upload-date>
    <isEditableFormDoc name="isEditableFormDoc" description="">
      <box/>
    </isEditableFormDoc>
    <documents name="documents" description=""/>
  </item>
</ad-documents>
  • 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-04T07:03:05+00:00Added an answer on June 4, 2026 at 7:03 am

    The solution is simple:

    Just replace:

     <xsl:for-each select="//ad-documents/item">
    

    with

     <xsl:for-each select=
        "//ad-documents/item
                [$selectedLetter eq upper-case(substring(documentName, 1, 1) ]">
    

    You can add after this xsl:for-each

    <xsl:sequence select=
     "'YourErrorMessage'
         [not(//ad-documents/item
                    [$selectedLetter eq upper-case(substring(documentName, 1, 1) ]
    
             )
          ]"
     />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the below code I'm trying to loop through each child node and append
I'm trying to loop through the results from the Last.fm API but it's not
I'm trying to loop through a sub array (which is part of a multidimensional
I am trying to loop through a directory of text files and combine them
I am trying to loop through a vectors elements and trying to find out
I am trying to loop through each line in a file and find and
I am trying to loop through this external JSON file(locally stored), but I cannot
I'm trying to loop through a text file with a list of urls and
So I have an XML file that I am trying to loop through in
I'm using smarty for my site, and I'm trying to loop through an array

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.