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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:14:45+00:00 2026-05-27T15:14:45+00:00

I have the following XML: <root> <row> <elem>Timestamp</elem> <elem>ERB.CHW.BTU_CV</elem> <elem>ERB.CHW.BTU1_CV</elem> <elem>ERB.HW.BTU_CV</elem> <elem>ERB.HW.BTU1_CV</elem> <elem>ERB.KW.DEMAND_CV</elem> <elem>ERB.KWH.MT_CV</elem>

  • 0

I have the following XML:

<root>
  <row>
    <elem>Timestamp</elem>
    <elem>ERB.CHW.BTU_CV</elem>
    <elem>ERB.CHW.BTU1_CV</elem>
    <elem>ERB.HW.BTU_CV</elem>
    <elem>ERB.HW.BTU1_CV</elem>
    <elem>ERB.KW.DEMAND_CV</elem>
    <elem>ERB.KWH.MT_CV</elem>
    <elem></elem>
  </row>
  <row>
    <elem>2011/09/30 11:21:13.9062</elem>
    <elem>2.307609E+09</elem>
    <elem>1880067</elem>
    <elem>1.068635E+08</elem>
    <elem>1340.386</elem>
    <elem>448.8</elem>
    <elem>1427723</elem>
    <elem></elem>
  </row>
</root>

I want to alter it such that the first <row> defines new elements (via <elem>) and each non-empty <elem> that follows provides values – such as:

<root>
  <row>
    <Timestamp>2011/09/30 11:21:13.9062</Timestamp>
    <ERB.CHW.BTU_CV>2.307609E+09</ERB.CHW.BTU_CV>
    <ERB.CHW.BTU1_CV>1880067</ERB.CHW.BTU1_CV>
    <ERB.HW.BTU_CV>1.068635E+08</ERB.HW.BTU_CV>
    <ERB.HW.BTU1_CV>1340.386</ERB.HW.BTU1_CV>
    <ERB.KW.DEMAND_CV>448.8</ERB.KW.DEMAND_CV>
    <ERB.KWH.MT_CV>1427723</ERB.KWH.MT_CV>
  </row>
</root>

Two things to note:

  1. Notice how blank <elem> elements are removed from the source structure.
  2. This should work for any number of <row> nodesets.

I feel like this should be simple, but I’m struggling to even know where to begin. Help?

EDIT: RE: #2 above, I am not looking to duplicate the initial <row> nodeset (which is used to define the new elements). Rather, the solution should work for any <row> nodeset that contains data points (i.e., if the second <row> nodeset was duplicated 5 times in a row).

  • 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-27T15:14:46+00:00Added an answer on May 27, 2026 at 3:14 pm

    This transformation:

    <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:variable name="vElems" select=
         "/*/row[1]/elem[normalize-space()]"/>
    
    
     <xsl:template match="/*">
      <root>
        <xsl:apply-templates select="row[position() >1]"/>
      </root>
     </xsl:template>
    
     <xsl:template match="row">
      <row>
       <xsl:apply-templates select="$vElems">
        <xsl:with-param name="pValues"
          select="elem"/>
        </xsl:apply-templates>
      </row>
     </xsl:template>
    
     <xsl:template match="elem">
      <xsl:param name="pValues"/>
      <xsl:variable name="vPos" select="position()"/>
    
      <xsl:element name="{.}">
       <xsl:value-of select="$pValues[$vPos]"/>
      </xsl:element>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the following XML document (the provided plus one more data row):

    <root>
        <row>
            <elem>Timestamp</elem>
            <elem>ERB.CHW.BTU_CV</elem>
            <elem>ERB.CHW.BTU1_CV</elem>
            <elem>ERB.HW.BTU_CV</elem>
            <elem>ERB.HW.BTU1_CV</elem>
            <elem>ERB.KW.DEMAND_CV</elem>
            <elem>ERB.KWH.MT_CV</elem>
            <elem></elem>
        </row>
        <row>
            <elem>2011/09/30 11:21:13.9062</elem>
            <elem>2.307609E+09</elem>
            <elem>1880067</elem>
            <elem>1.068635E+08</elem>
            <elem>1340.386</elem>
            <elem>448.8</elem>
            <elem>1427723</elem>
            <elem></elem>
        </row>
        <row>
            <elem>2011/09/31 11:22:33.9063</elem>
            <elem>3.418609E+10</elem>
            <elem>1991073</elem>
            <elem>1.068635E+08</elem>
            <elem>1340.386</elem>
            <elem>452.5</elem>
            <elem>169578</elem>
            <elem></elem>
        </row>
    </root>
    

    produces the wanted, correct result:

    <root>
       <row>
          <Timestamp>2011/09/30 11:21:13.9062</Timestamp>
          <ERB.CHW.BTU_CV>2.307609E+09</ERB.CHW.BTU_CV>
          <ERB.CHW.BTU1_CV>1880067</ERB.CHW.BTU1_CV>
          <ERB.HW.BTU_CV>1.068635E+08</ERB.HW.BTU_CV>
          <ERB.HW.BTU1_CV>1340.386</ERB.HW.BTU1_CV>
          <ERB.KW.DEMAND_CV>448.8</ERB.KW.DEMAND_CV>
          <ERB.KWH.MT_CV>1427723</ERB.KWH.MT_CV>
       </row>
       <row>
          <Timestamp>2011/09/31 11:22:33.9063</Timestamp>
          <ERB.CHW.BTU_CV>3.418609E+10</ERB.CHW.BTU_CV>
          <ERB.CHW.BTU1_CV>1991073</ERB.CHW.BTU1_CV>
          <ERB.HW.BTU_CV>1.068635E+08</ERB.HW.BTU_CV>
          <ERB.HW.BTU1_CV>1340.386</ERB.HW.BTU1_CV>
          <ERB.KW.DEMAND_CV>452.5</ERB.KW.DEMAND_CV>
          <ERB.KWH.MT_CV>169578</ERB.KWH.MT_CV>
       </row>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say we have the following XML: <root> <row> <column>row 1 col 1</column> <column>row
I have the following xml, xmlDoc that looks like this: <root> <a> <Row> </a>
I have the following xml: <Root> <Item> <CityCode>ALV</CityCode> <AirportCode>ALV</AirportCode> <CityName>ANDORRA LA VELLA</CityName> <AirportName>Andorra La
I have the following XML Schema: <Root> <EventSet> <Event> <id> //random id </id> <time>
I have the following XML <ns0:Root xmlns:ns0=http://Map_Sample.Input_Schema> <Number1> </Number1> <Number2>11</Number2> <Number3>12</Number3> </ns0:Root> In this
I have the following XML: <root> <section> <item name=a> <uuid>1</uuid> </item> </section> <section> <item
I have the following input XML: <root age=1> <description>some text</description> <section> <item name=a> <uuid>1</uuid>
I have the following XML structure <root> <OuterLevel> <Node> <Name>NodeA</Name> </Node> <Node> <Name>NodeB</Name> <Node>
I have the following xml: <root> <Element1> <Hierarchy attr=value/> <Hierarchy attr=value/> <Hierarchy attr=value/> <Hierarchy
I have the following xml and want to insert additional xml into it: <root>

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.