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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:12:44+00:00 2026-06-18T06:12:44+00:00

I’m trying to insert an if-else statement inside of a foreach statement in XSLT.

  • 0

I’m trying to insert an if-else statement inside of a foreach statement in XSLT.
The idea is , if the node exist it will insert a line break.This is what I have so far

<xsl:for-each select="Books/Publisher/[BookTitle]">
                  <strong>
                    <xsl:value-of select=" BookTitle " />
                  </strong>
<xsl:if test=" Books/Publisher/BookTitle">!= ''">
        <br/>  
      </xsl:if>
</xsl:for-each>

The problem is that the line break tag does not appear when I insert an if-else statement but will only work when I remove the if else entirely.Can someone explain to me why this is happening,because I’ve checked the node is there and inserting the linebreak should work.So there must be something wrong with the if-else inside the foreach loop.

  • 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-18T06:12:45+00:00Added an answer on June 18, 2026 at 6:12 am

    I think what you are going for is this:

    <xsl:for-each select="Books/Publisher[BookTitle]">
      <strong>
        <xsl:value-of select="BookTitle" />
      </strong>
      <xsl:if test="BookTitle != ''">
        <br/>
      </xsl:if>
    </xsl:for-each>
    

    But if I understand correctly, it looks like all you’re really trying to do is output all the non-blank book titles, followed by line breaks, so perhaps this would be a better approach:

    <xsl:for-each select="Books/Publisher/BookTitle[. != '']">
      <strong>
        <xsl:value-of select="." />
      </strong>
      <br/>
    </xsl:for-each>
    

    Or better yet:

    <xsl:apply-templates select="Books/Publisher/BookTitle[. != '']" />
    
    <!-- .....  (separate template in the XSLT) -->
    <xsl:template match="BookTitle">
      <strong>
        <xsl:value-of select="." />
      </strong>
      <br/>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to insert this query with mysql_query INSERT INTO um_group_rights (`um_group_id`,`cms_usecase_id`,`um_right_id`) VALUES (2,1,1)
I'm trying this script to insert only a unique date into a text file,
I'm trying to insert data into a database that I have on my server.
I am trying to update a value if record exists else insert the values
I'm trying to insert a variable mathematical operator into a if statement, an example
I am trying to insert data into my SQLite database. I have imported all
I'm trying a simple if/else statement with Javascript & PHP (with jQuery cookie plugin
I have a database table I am trying to do an UPDATE/INSERT to with
I am trying to bind params to a INSERT INTO MySQLi prepared statement if
I'm trying to write a MySQL statement to insert information to a table: $insert

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.