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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:15:58+00:00 2026-05-27T21:15:58+00:00

I bet this is a simple question. Im trying to style my xml file

  • 0

I bet this is a simple question.

Im trying to style my xml file with XSL. And the thing I am trying to do is that when an element in my XML file is missing, I want the xsl to output ” Missin Element”

I manage to create an string that says no data in element, but thats when I don’t have any data in the element but the element still exist.

I pasting my xml file to explain better

<autoads>
    <ad>
        <type>1</type>
        <name>Honda</name>
        <model>XL 1000 V</model>
        <regyear>2001</regyear>
        <price>129900</price>
        <adtext>2001 Honda XL 1000 V, 8.900 km. hög vindruta. Pris 129.900kr,-.  </adtext>
        <addate>20020115</addate>
        <volume>1000</volume>

    </ad>
    <ad>
        <type>2</type>
        <name>Nissan</name>
        <model>Almera 1.4S</model>
        <regyear>1997</regyear>
        <price>119000</price>
        <adtext>1997 Nissan Almera 1.4S, 5 dörrar, met, 70.000 km. el.spegel/fönster, galv. kaross, c.lås, startspärr, airbag, nedfällb. baks. ABS, ute temp. R/CD, alarm, d.fäste, v.säten, s/v-hj.  EU-godk. full service, servo. Pris 119.000 kr,-.  </adtext>
        <addate>20020118</addate>
        <volume>0</volume>
        <category>5 dörrar</category>
    </ad>
</autoads>

As you se the element category is missing in the first one,

Thats what im trying to output with an xsl string, that it should print out ” category is missing”

Thanks for all help.

  • 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-27T21:15:58+00:00Added an answer on May 27, 2026 at 9:15 pm

    You’ll need to specify which elements you’re expecting and test for their existence. In the simplest case, use something like this:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="ad">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
                <xsl:if test="not(category)">
                    <xsl:comment>category is missing</xsl:comment>
                </xsl:if>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    This outputs a comment in place of the missing node, but you could easily modify it to output an element or simply text.

    For a more complete solution, create a list of the required elements and use the document function to verify the presence of each item in this list:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:m="m">
        <xsl:output method="xml" indent="yes"/>
        <m:req>type</m:req>
        <m:req>name</m:req>
        <m:req>model</m:req>
        <m:req>regyear</m:req>
        <m:req>price</m:req>
        <m:req>adtext</m:req>
        <m:req>addate</m:req>
        <m:req>volume</m:req>
        <m:req>category</m:req>
        <xsl:variable name="required" select="document('')/*/m:req"/>
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
        <xsl:template match="ad">
            <xsl:variable name="this" select="."/>
            <xsl:copy>
                <xsl:apply-templates select="@*"/>
                <xsl:for-each select="$required">
                    <xsl:variable name="search"
                        select="$this/*[name()=current()]"/>
                    <xsl:if test="$search">
                        <xsl:apply-templates select="$search"/>
                    </xsl:if>
                    <xsl:if test="not($search)">
                        <xsl:comment>
                            <xsl:value-of select="concat(., ' is missing')"/>
                        </xsl:comment>
                    </xsl:if>
                </xsl:for-each>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bet this is easy but been trying for a while and can't seem
I bet this is incredibly simple, but I looked through the documentation on barplot()
I bet this has a simple answer.. Let's say I have a Post model
I bet this is super simple and easy but can't find a basic example
Warning: This is a not very serious question/discussion that I am posting... but I
I bet this has been answered many times over, but... For a simple situation
Simple question for I bet a not so simple answer. Think of a project
I bet somebody has solved this before, but my searches have come up empty.
I bet I've got elementary question, but I couldn't solve it for two nights.
I'm trying to design a model for a application allowing 2 people to bet

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.