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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:35:39+00:00 2026-05-24T06:35:39+00:00

I have the following XML: <?xml version="1.0" encoding="UTF-8"?> <Data> <Set> <Tables> <Table> <Tablehead> <C>Name</C>

  • 0

I have the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<Data>
  <Set>
<Tables>
  <Table>
    <Tablehead>
      <C>Name</C>
      <C>FirstName</C>
      <C>Address</C>
      <C>Zip</C>
      <C>City</C>
      <C>State</C>
    </Tablehead>
    <Rows>
      <Person>
        <C>Miller</C>
        <C>John</C>
        <C>Squires Circle</C>
        <C>88034</C>
        <C>Boulder</C>
        <C>Colorado</C>
      </Person>
    </Rows>
  </Table>
    </Tables>
  </Set>
</Data>

The element person can occur n-times. Now to properly work with that structure I have to rename the <C> tags first within <Person>.
I came up with this XSL:

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

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="Rows"> 
    <Rows>     
        <xsl:apply-templates select="Person"/>
    </Rows>
</xsl:template>

<xsl:template match="Person">
     <Person>
         <xsl:apply-templates select="C"/>                    
     </Person>   
</xsl:template>

<xsl:template match="/Data/Set/Tables/Table/Rows/Person/C">
    <xsl:variable name="nodePosition" select="position()" />
        <xsl:value-of select="parent::*/parent::*/parent::*/Tablehead/C[$nodePosition]"/>
</xsl:template>

</xsl:stylesheet>

But the output is always this:

<?xml version="1.0" encoding="UTF-8"?>
<Data>
  <Set>
  <Tables>
  <Table>
    <Tablehead>
      <C>Name</C>
      <C>FirstName</C>
      <C>Address</C>
      <C>Zip</C>
      <C>City</C>
      <C>State</C>
    </Tablehead>
    <Rows>
      <Person/>
    </Rows>
  </Table>
  </Tables>
  </Set>
</Data>

It looks fine but my <Person> element is always empty. What am I missing?

  • 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-24T06:35:40+00:00Added an answer on May 24, 2026 at 6:35 am

    The following stylesheet

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="Person/C">
        <xsl:variable name="index">
          <xsl:number/>
        </xsl:variable>
        <xsl:element name="{../../../Tablehead/C[position() = $index]}">
          <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
    
    </xsl:stylesheet>
    

    when applied to the input

    <?xml version="1.0" encoding="UTF-8"?>
    <Data>
      <Set>
    <Tables>
      <Table>
        <Tablehead>
          <C>Name</C>
          <C>FirstName</C>
          <C>Address</C>
          <C>Zip</C>
          <C>City</C>
          <C>State</C>
        </Tablehead>
        <Rows>
          <Person>
            <C>Miller</C>
            <C>John</C>
            <C>Squires Circle</C>
            <C>88034</C>
            <C>Boulder</C>
            <C>Colorado</C>
          </Person>
        </Rows>
      </Table>
        </Tables>
      </Set>
    </Data>
    

    outputs

    <?xml version="1.0" encoding="UTF-8"?><Data>
      <Set>
    <Tables>
      <Table>
        <Tablehead>
          <C>Name</C>
          <C>FirstName</C>
          <C>Address</C>
          <C>Zip</C>
          <C>City</C>
          <C>State</C>
        </Tablehead>
        <Rows>
          <Person>
            <Name>Miller</Name>
            <FirstName>John</FirstName>
            <Address>Squires Circle</Address>
            <Zip>88034</Zip>
            <City>Boulder</City>
            <State>Colorado</State>
          </Person>
        </Rows>
      </Table>
        </Tables>
      </Set>
    </Data>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following simplified XML structure: <?xml version="1.0" encoding="UTF-8"?> <ExportData> <TransportHeader> <Timestamp>2011-01-16 06:00:33</Timestamp>
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <game> <name>Space Blaster</name> <description></description> <version>1</version> <fullscreen>false</fullscreen>
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom'
I have XML shaped like the following: <?xml version=1.0 encoding=UTF-8?> <feed xmlns=http://www.w3.org/2005/Atom xmlns:openSearch=http://a9.com/-/spec/opensearch/1.1/ xmlns:docs=http://schemas.google.com/docs/2007
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have following XML schema: <?xml version=1.0 encoding=UTF-8 standalone=no?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:element name=content type=contentType/>
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
I have the following the layout file <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:app=http://schemas.android.com/apk/res/com.company android:layout_width=fill_parent
I have the following XML <?xml version=1.0 encoding=ISO-8859-1 ?> - <DEVICEMESSAGES> <VERSION xml=1 checksum=
I have following xml file: <?xml version = "1.0" ?> <Employee> <Emp_Id>E-001</Emp_Id> <Emp_Name>Vinod</Emp_Name> <Emp_E-mail>Vinod1@yahoo.com</Emp_E-mail>

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.