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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:59:16+00:00 2026-06-14T20:59:16+00:00

I have a XML File which contains user ids and names. I want to

  • 0

I have a XML File which contains user ids and names. I want to extract all elements where both of these attributes have a value.

This is my xml

<pens>
<pen id="A">
    <user name="USER1" email="USER1EMAIL" />
</pen>
<pen id="B">
    <user name="USER2" email="USER2EMAIL" />
</pen>
<pen id="C"></pen>
<pen id="D">
    <user name="USER3" email="USER3EMAIL" />
</pen>
</pens>

I need a out like this

A - USER1
B - USER2
D - USER3

I try it with XSL but I dont get it … can someone help please.
Thanks

  • 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-14T20:59:18+00:00Added an answer on June 14, 2026 at 8:59 pm

    When this XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output omit-xml-declaration="no" indent="yes" method="text" />
      <xsl:strip-space elements="*" />
    
      <xsl:template match="user[@name][@email]">
        <xsl:value-of select="parent::*/@id" />
        <xsl:text> - </xsl:text>
        <xsl:value-of select="@name" />
        <xsl:text>&#10;</xsl:text>
      </xsl:template>
    
    </xsl:stylesheet>
    

    …is applied against your original XML:

    <pens>
      <pen id="A">
        <user name="USER1" email="USER1EMAIL"/>
      </pen>
      <pen id="B">
        <user name="USER2" email="USER2EMAIL"/>
      </pen>
      <pen id="C"/>
      <pen id="D">
        <user name="USER3" email="USER3EMAIL"/>
      </pen>
    </pens>
    

    …the wanted result is produced:

    A - USER1
    B - USER2
    D - USER3
    

    Explanation:

    • We set the @method attribute of the <xsl:output> element to have a value of text (since we are interested in text results).

    • One template matches <user> elements that have @name and @email attributes defined.

    • When one such <user> element is found, we output the value of its parent element’s @id attribute, a dash, the value of the element’s @name attribute, and finally, a newline character.

    Saving this result to a file depends on which XSLT processor you are using. If you run your transformations via the command line (e.g., the way xsltproc does), you can do something like this:

    $ xsltproc t.xsl input.xml > output.xml

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

Sidebar

Related Questions

I have a XML-file, which contains the data of a calendar. I want to
We have a PageRoles xml file which contains the page path and the user
I have written xml file which contains html tags as element like <component> <input
I have a xml file which contains arabic characters.When i try to parse a
I have an XML file of(30GB) which contains 2 classes of data, The data
I have a problem parsing a XML file which contains special characters like ,
I have a large XML file which in the middle contains the following: <ArticleName>Article
I have an xml file which contains query details like <queries> <query> <name>GetStudentById</name> <statement>select
I have a xml file which I need to open with Microsoft Word 2007.
I have this xml file which has text init. i.e Hi my name is

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.