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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:29:40+00:00 2026-05-31T12:29:40+00:00

I have a table schema which has some meta field data which I need

  • 0

I have a table schema which has some meta field data which I need to pull down to the row level.

So this …

<tables>
    <table name="T01">
        <columns>
            <column name="F01">
                <heading>Field 1</heading>
            </column >
            <column name="F02">
                <heading>Field 2</heading>
            </column>
        </columns>
        <rows>
            <row>
                <field name="F01">AAAAA</field>
                <field name="F02">BBBBB</field>
            </row>
            <row>
                <field name="F01">DDDDD</field>
                <field name="F02">EEEEE</field>
            </row>
        </rows>
    </table>
    <table name="T02">
        <!-- ... -->
    </table>
</tables>

should become this …

<tables>
    <table name="T01">
        <rows>
            <row>
                <field name="F01">
                    <heading>Field 1</heading>
                    <value>AAAAA</value>
                </field>
                <field name="F02">                    
                    <heading>Field 2</heading>  
                    <value>BBBBB</value>
                </field>
            </row>
            <row>
                <field name="F01">
                    <heading>Field 1</heading>
                    <value>DDDDD</value>
                </field>
                <field name="F02">                    
                    <heading>Field 2</heading>  
                    <value>EEEEE</value>
                </field>
            </row>
        </rows>
    </table>
    <table name="T02">
        <!-- ... -->
    </table>
</tables>

I am sure there are tons of simple ways to do this with XSLT, but due to my tool, I really need to retrieve the column heading via a key(). So something like this …

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

  <!-- This won't work but if it did ... -->
  <xsl:key name="field-heading"
          match="../../columns/column/heading"
          use="../@name" />

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


  <xsl:template match="field">
    <field name="{@name}">
      <heading>
        <xsl:value-of select="key('field-heading', @name)"/>
      </heading>
      <value>
        <xsl:value-of select="."/>
      </value>
    </field>
  </xsl:template>

  <xsl:template match="columns"/>

</xsl:stylesheet>

But the xsl:key match attribute doesn’t allow the parent axis and I am not sure if there are any other ways make it fit.

  • 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-31T12:29:42+00:00Added an answer on May 31, 2026 at 12:29 pm

    A slightly simpler solution:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:key name="kColByNames" match="column" use=
      "concat(../../@name, '+', @name)"/>
    
     <xsl:template match="node()|@*">
         <xsl:copy>
           <xsl:apply-templates select="node()|@*"/>
         </xsl:copy>
     </xsl:template>
    
     <xsl:template match="field">
      <xsl:copy>
       <xsl:copy-of select="@*"/>
       <heading>
         <xsl:value-of select=
          "key('kColByNames', concat(ancestor::table[1]/@name, '+', @name))"/>
       </heading>
       <value><xsl:value-of select="."/></value>
      </xsl:copy>
     </xsl:template>
     <xsl:template match="columns"/>
    </xsl:stylesheet>
    

    When this transformation is applied on the provided XML document:

    <tables>
        <table name="T01">
            <columns>
                <column name="F01">
                    <heading>Field 1</heading>
                </column>
                <column name="F02">
                    <heading>Field 2</heading>
                </column>
            </columns>
            <rows>
                <row>
                    <field name="F01">AAAAA</field>
                    <field name="F02">BBBBB</field>
                </row>
                <row>
                    <field name="F01">DDDDD</field>
                    <field name="F02">EEEEE</field>
                </row>
            </rows>
        </table>
        <table name="T02">
            <!-- ... -->
        </table>
    </tables>
    

    the wanted, correct result is produced:

    <tables>
       <table name="T01">
          <rows>
             <row>
                <field name="F01">
                   <heading>Field 1</heading>
                   <value>AAAAA</value>
                </field>
                <field name="F02">
                   <heading>Field 2</heading>
                   <value>BBBBB</value>
                </field>
             </row>
             <row>
                <field name="F01">
                   <heading>Field 1</heading>
                   <value>DDDDD</value>
                </field>
                <field name="F02">
                   <heading>Field 2</heading>
                   <value>EEEEE</value>
                </field>
             </row>
          </rows>
       </table>
       <table name="T02"><!-- ... --></table>
    </tables>
    

    Explanation: Overriding the identity rule and using a composite key — a column is identified by the pair of its name attribute and the name attribute of its grandparent table.

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

Sidebar

Related Questions

I have a situation like this. I have schema which has high level user
Say I have this table schema. ID AccNo Amount Say I have this data
I have a table that has this schema: create table mytable (creation_date timestamp, value
I have a table schema which is essentially a bunch of transaction info with
I have a table named Info of this schema: int objectId; int time; int
I have a table in PostgreSQL where the schema looks like this: CREATE TABLE
I have an orders table with a schema like this. CREATE TABLE orders (
I have a table that got into the db_owner schema, and I need it
I have database schema for an integration project in which I need to be
I have a JIRA environment which already has some information and i'm trying to

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.