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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:58:51+00:00 2026-06-09T05:58:51+00:00

I have an input XML as below <testing> <subject ref=yes> <firstname> tom </firstname> </subject>

  • 0

I have an input XML as below

<testing>
<subject ref="yes">
 <firstname>
    tom
 </firstname>
</subject>
<subject ref="no">
 <firstname>
    sam
</firstname>
</subject>
</testing>

I am expecting my output should be.

if the subject has ref as yes. I will get the name value. Else if the ref (no) i won’t get element

<testing>
<firstname>
   tom
</firstname>
</testing>

Please guide me here.

  • 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-09T05:58:52+00:00Added an answer on June 9, 2026 at 5:58 am

    This can be achieved by building on top of the identity transform. Firstly, you would need a template to ignore subject elements with a @ref of ‘no’

    <xsl:template match="subject[@ref='no']" />
    

    And for subject elements with a @ref of ‘yes’ you have another template to output just its children

    <xsl:template match="subject[@ref='yes']">
       <xsl:apply-templates select="node()"/>
    </xsl:template>
    

    In fact, if @ref could only ever be ‘yes’ or ‘no’ you could simplify this template match to just <xsl:template match="subject"> as this would match all elements which don’t have a @ref of ‘no’

    Here is the full XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="xml" indent="yes"/>
    
       <xsl:template match="subject[@ref='no']" />
    
       <xsl:template match="subject">
          <xsl:apply-templates select="node()"/>
       </xsl:template>
    
       <xsl:template match="@*|node()">
          <xsl:copy>
             <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    </xsl:stylesheet>
    

    When applied to your sample XML, the following is output

    <testing>
    <firstname> tom </firstname>
    </testing>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input xml as below <maindocument> <first> <testing>random text</testing> <checking>random test</checking> </first>
Let's assume, you have the xml below. The goal is to group by FirstName
I have a query in the xml and xslt The below is the Input
Below is My input XML <First> <practice-session note=yes> <lessons>13000</lessons> <lessons>15000</lessons> <lessons>note</lessons> </practice-session> <practice-repeats note=yes>>
I have an XML input as shown below: <?xml version=1.0 encoding=utf-8?> <Content> <section name=FileID/>
i have input xml as <content> <date> <day>14</day> <month>06</month> <year>2012</year> </date> </content> want it
I have the following input XML: <root age=1> <description>some text</description> <section> <item name=a> <uuid>1</uuid>
This is my input xml. The xml can have maximunm three nodes and minimum
I have this use case of an xml file with input like Input: <abc
I have written xml file which contains html tags as element like <component> <input

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.