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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:30:53+00:00 2026-05-15T15:30:53+00:00

Using this input XML: <?xml version=1.0 encoding=utf-8?> <Employees> <Employee ID=1> <FirstName>Klaus</FirstName> <LastName>Salchner</LastName> </Employee> <Employee

  • 0

Using this input XML:

<?xml version="1.0" encoding="utf-8"?>
<Employees>
   <Employee ID="1">
      <FirstName>Klaus</FirstName>
      <LastName>Salchner</LastName>
   </Employee>
   <Employee ID="2">
      <FirstName>Peter</FirstName>
      <LastName>Pan</LastName>
   </Employee>
</Employees>

How would you get this output:

<Employees>
    <FirstName>
        <Employee>Klaus</Employee>
        <Employee>Peter</Employee>
    </FirstName>
    <LastName>
        <Employee>Salchner</Employee>
        <Employee>Pan</Employee>
    </LastName>
</Employees>

But, if you don’t know how many fields there are going to be in the Employee elements – however, lets assume that the same elements (here being, FirstName and LastnName) will definately be present in every Employee element.

The best I’ve got is:

<Employees>
    <xsl:for-each select="*/Employee/.">
        <xsl:value-of select=".">
            <xsl:value-of select="./." />
        </xsl:value-of>
    </xsl:for-each>
</Employees>

And I know that’s wrong!

  • 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-15T15:30:54+00:00Added an answer on May 15, 2026 at 3:30 pm

    Well, I worked it out in the end – basically I need a for-each for the elements in the first Employee and assign a variable inside the for-each to the position() value.

    Then, in a second, nested for-each, I loop through the outer Employee elements.

    For each Employee element I use the variable (which contains the “row” of the inner element) to index it’s inner element.

    Something like:

    <xsl:for-each select="*/Employee[1]/.">
        <tr>
            <xsl:variable name="row" select="position()" />
            <xsl:for-each select="/*/Employee">
                <td>
                    <xsl:value-of select=".[$row]/."/>
                </td>
            </xsl:for-each>
        </tr>
    </xsl:for-each>
    

    I will admit, mine is a little more concise, but that’s the gist.

    In short (deep breath) loop through the list of elements of the first outer element. For each one, loop through the outer elements and use the index of the inner elements to pick the inner elements sequentially.

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

Sidebar

Related Questions

I have a input file Main.xml <?xml version=1.0 encoding=utf-8 ?> <Employees> <Employee> <id name=id>1</id>
I'm using this wsdl-file to describe my webservice: <?xml version=1.0 encoding=UTF-8 ?> <wsdl:definitions targetNamespace=http://www.myapproach.de/knowledgebase
I have a style sheet like this <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform> <xsl:param
I have the following XML file: <?xml version='1.0' encoding='utf-8'?> <Answers> <Question1 q=What is your
I have the following XML file: <?xml version='1.0' encoding='utf-8'?> <Answers> <Question1 q=What is your
I'm trying to parse this xml input using the bash utility xpath : <?xml
I am using XML::LibXML (Ver: 1.70). My xml input file looks like this: <?xml
I have the following small file to reproduce the warning: <?xml version=1.0 encoding=UTF-8?> <beans
Using MATLAB, I have this code: value = input('>> Enter a value: '); and
Using Zend_Form, how would I create form elements like this: <input type=text name=element[1] value=

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.