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

  • Home
  • SEARCH
  • 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 7075655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:12:12+00:00 2026-05-28T06:12:12+00:00

I need to write a clause into my xslt that says if an element

  • 0

I need to write a clause into my xslt that says if an element is present display text node and if it is not present, display nothing. I can find how to write if the text node is a particular word but not if the element is present.

Any advice is much appreciated.

PS: new to xslt/xml etc

Eg: XML represents a book containing pages. One version of the page has a header. Underneath is a table with four columns and 20 rows. Under this is a footer. This footer is not on the other version of the page. My xslt needs to transform the xml into a webpage representing this visually.

the xml therefore has an element of <Footer> which has a minOccurs of 0 in the schema.

  • 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-05-28T06:12:13+00:00Added an answer on May 28, 2026 at 6:12 am

    This can be done by omitting the comparison e.g.

    <xsl:if test='root/element'>
    

    However, a cleaner way ultimately getting what you want is to use xsl:templates

    So for xml

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <page>
        <title>Franks</title>
        <header>header text</header>
        <bodytext>here is the body text</bodytext>
      </page>
      <page>
        <title>Joes</title>
        <footer>footer text</footer>
        <bodytext>here is the body text2</bodytext>
      </page>
    </root>
    

    The xsl

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    >
        <xsl:output method="xml" indent="yes"/>
    
        <xsl:template match="/">
    
          <xsl:apply-templates select="page"></xsl:apply-templates>
        </xsl:template>
    
      <xsl:template match="page">
        <h1>
          <xsl:value-of select="title"/>
        </h1>
        <p>
          <xsl:value-of select="bodytext"/>
        </p>
        <xsl:apply-templates select="footer"/>
      </xsl:template>
    
      <xsl:template match="footer">
        <p>
          <xsl:value-of select="."/>
        </p>
      </xsl:template>
    </xsl:stylesheet>
    

    illustrates the way this can be done.
    check out w3schools xpath tutorial for more information on selecting.

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

Sidebar

Related Questions

I need to write a conditional statement in my where clause that uses different
I need write an update statement that used multiple tables to determine which rows
I need to write a Java Comparator class that compares Strings, however with one
I need to write a Delphi application that pulls entries up from various tables
I need to write code that picks up PGP-encrypted files from an FTP location
I need to write an extension method on a byte[]. Is that possible?
I am starting to write an installer which will use the SqlScript -element. That
I need write a set of clauses that take a list of integer lists
I need to write a simple query in mySQL that would use MIN() in
I need to write a program that accepts a basic SQL select statement and

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.