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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:16:56+00:00 2026-06-07T23:16:56+00:00

I have this XML: <root> <tab name=Detail> <section name=mysection> <items level=1> <Idx_name>9</Idx_name> <Type>mytype</Type> <item

  • 0

I have this XML:

    <root>   
      <tab name="Detail">
        <section name="mysection">
          <items level="1">
            <Idx_name>9</Idx_name>
            <Type>mytype</Type>
            <item name="myname">
              <Grams um="(g)">9,0</Grams>
              <Pre-infusion>Max</Pre-infusion>
            </item>
            <Std._Mode>On</Std._Mode>
            <Price>100</Price>
          </items>
        </section>   
    </tab> 
</root>

and this XSLT:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="node()">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates select="node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="items/*">
    <xsl:choose>
      <xsl:when test="not(name()='item')">
        <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:copy>
          <xsl:copy-of select="@*"/>
          <xsl:value-of select="."/>
        </xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Now, what I want is:

<root>
  <tab name="Detail">
    <section name="mysection">
      <items level="1" Idx_name="9" Type="mytype" Std._Mode="On" Price="100">
        <item name="myname">9,0Max</item>
      </items>
    </section>
  </tab>
</root>

I obtain the error: “An attribute cannot be added after a child”

Unluckily, I can not change the order of elements in the node items of my original XML

How can I do it ?

Thanks

Ivan

  • 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-07T23:16:58+00:00Added an answer on June 7, 2026 at 11:16 pm

    Make sure you process the elements first you want to transform into attributes e.g. with XSLT 2.0 where you can process sequences which have a order you can simply do

    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>
    
    <xsl:template match="@* | node()">
      <xsl:copy>
        <xsl:apply-templates select="@*, node()"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="items">
      <xsl:copy>
        <xsl:apply-templates select="@*, * except item, item"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="items/*[not(self::item)]">
      <xsl:attribute name="{name()}" select="."/>
    </xsl:template>
    
    <xsl:template match="items/item">
      <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <xsl:value-of select="."/>
      </xsl:copy>
    </xsl:template>
    
    </xsl:stylesheet>
    

    With XSLT 1.0 you would need to spell out several apply-templates in the order you want.

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

Sidebar

Related Questions

ok i have this xml <roots> <root> <name>first</name> <item type='test'><something>A</something></item> <item type='test'><something>B</something></item> <item type='test'><something>C</something></item>
So I have this XML doc: <?xml version=1.0 encoding=UTF-8?> <Root> <Item> <URL>http://www.mysite.com/page?id=1</URL> </Item> </Root>
I have this XML: <root> <data name=lnkViewResultResource1.Text xml:space=preserve> <value>bekijk de resultaten</value> </data> <data name=lnkVoteResource1.Text
I have this below xml <root> <s> <name>self-1</name> <parents> <s> <name>p-1-2</name> <parents> <s> <name>p-1-2-1</name>
Suppose I have this XML document... <root> <str name=My node's attribute>My string's value</str> </root>
So say I have this XML file: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root> <Category Name=Tasties>
I have this source XML: <?xml version=1.0?> <root> <item1> <name>test</name> <price>160</price> <stock>4</stock> <country>Belgium</country> </item1>
I am parsing this xml <Root><Status>1</Status><Message>Get call Successful</Message><StatusCode></StatusCode><Item type = 'all' subtype = '0'
I have this XML: <root> <items> <item1> <tag1>1</tag1> <sub> <sub1>10 </sub1> <sub2>20 </sub2> </sub>
i have this XML document: <?xml version=1.0 encoding=UTF-16?> <root> <items> <item1> <tag1>1</tag1> <tag2>2</tag2> <tag3>3</tag3>

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.