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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:06:53+00:00 2026-06-18T03:06:53+00:00

Hello XML gurus and pros. I have a question how to style an xml

  • 0

Hello XML gurus and pros. I have a question how to style an xml tree if the tree is like that:

 1. ROW

Name
Surname
Type

 2. ROW

Name
Surname
Type

 3. ROW

ID
Name
Surname

I need to write xslt code that it show ROW 1(famous) and ROW 2(famous), but did not show ROW 3, and filter all ROW that did not have ID field in the tree, so answer must be that code will show Row1 and Row2. So how to do that ?
Code example here:
Some example, i can’t provide original xml file, because it’s secure information. Thanks for reply try to give you example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<testdocument>
<famous>
<name>Bob</name>
<surname>Bobby</surname>
<type>Human</type>
</famous>
<famous>
<name>Ted</name>
<surname>Teddy</surname>
<type>Human</type>
</famous>
<famous>
<name>Snake</name>
<surname>Anaconda</surname>
<type>Reptile</type>
<ID>ANIMAL</ID>
</famous>
</testdocument>

And i need to output famous leaf first and second but not ouput third leaf where ID is set to something. So i need output all but not famous leaf where is ID set to something, hope that i asked correctly. The possible ouput:

Bob
Bobby
Human

Ted
Teddy
Human

And that’s it.

This is the XSLT I have so far:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">

<html>
<head>
<title></title>
</head>
<body>
<!-- Here i think something must be written as condition that 
     ID field not be taken, and ROw3 name and surname not be shown too..-->
<xsl:for-each select="famous[ID != 0]"> 
<xsl:value-of select="NAME"/>
<xsl:value-of select="SURNAME"/>
<xsl:value-of select="TYPE"/>
</xsl:for-each>
</body>
</html>

</xsl:template>
</xsl:stylesheet>
  • 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-18T03:06:55+00:00Added an answer on June 18, 2026 at 3:06 am

    Please try the following XSLT:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
      <xsl:output method="html"/>
      <xsl:template match="/">
        <html>
          <head>
            <title></title>
          </head>
          <body>
            <xsl:apply-templates select="testdocument/famous[not(ID)]" />
            <pre>
              <xsl:apply-templates select="*" mode="print" />
            </pre>
          </body>
        </html>
      </xsl:template>
    
      <xsl:template match="famous">
        <xsl:apply-templates select="*" />
        <br />
      </xsl:template>
    
      <xsl:template match="famous/*">
        <xsl:value-of select="."/>
        <br />
      </xsl:template>
    
      <xsl:template match="*" mode="spaces">
        <xsl:text>&#xA0;&#xA0;&#xA0;</xsl:text>
      </xsl:template>
    
      <xsl:template match="*" mode="print">
        <xsl:apply-templates select="ancestor::*" mode="spaces" />
        <xsl:value-of select="concat('&lt;', local-name(), '&gt;')"/>
        <xsl:if test="*">
          <xsl:text>&#xA;</xsl:text>
        </xsl:if>
    
        <xsl:apply-templates select="node()" mode="print" />
    
        <xsl:if test="*">
          <xsl:apply-templates select="ancestor::*" mode="spaces" />
        </xsl:if>
        <xsl:value-of select="concat('&lt;/', local-name(), '&gt;')"/>
        <xsl:text>&#xA;</xsl:text>
      </xsl:template>
    
      <xsl:template match="text()[not(normalize-space())]" mode="print" />
    </xsl:stylesheet>
    

    Result when run on your sample data:

    <html>
      <head>
        <META http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title></title>
      </head>
      <body>Bob<br>Bobby<br>Human<br><br>Ted<br>Teddy<br>Human<br><br><pre>&lt;testdocument&gt;
       &lt;famous&gt;
          &lt;name&gt;Bob&lt;/name&gt;
          &lt;surname&gt;Bobby&lt;/surname&gt;
          &lt;type&gt;Human&lt;/type&gt;
       &lt;/famous&gt;
       &lt;famous&gt;
          &lt;name&gt;Ted&lt;/name&gt;
          &lt;surname&gt;Teddy&lt;/surname&gt;
          &lt;type&gt;Human&lt;/type&gt;
       &lt;/famous&gt;
       &lt;famous&gt;
          &lt;name&gt;Snake&lt;/name&gt;
          &lt;surname&gt;Anaconda&lt;/surname&gt;
          &lt;type&gt;Reptile&lt;/type&gt;
          &lt;ID&gt;ANIMAL&lt;/ID&gt;
       &lt;/famous&gt;
    &lt;/testdocument&gt;
    </pre>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have an XML document like this: <root> <elem name=Greeting> Hello </elem> <elem
If I have some xml like this: <mynode> <mysubnode> <mysubsubnode>hello world</mysubsubnode> some more text
Hello I have a xml document in string that I am trying to post
I have XML like <A> <B> <C> Hello World </C> </B> </A> I want
I have an XML document with some sample content like this: <someTag> <![CDATA[Hello World]]>
I have a xml file for example, <title> hello <name> hi </name> <street> id
Hello I have a xml file from whihc i would like ot have a
I have XML in the form of a String that contains <message>HELLO!</message> How can
I have an XML file which will output a string: <mystring> <manipulate type=caps> <string>Hello
Hello I have an XML code like this: <article> <title><![CDATA[IEEE Transactions on]]></title> <articleinfo> <articleseqnum>13</articleseqnum>

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.