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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:12:32+00:00 2026-05-30T10:12:32+00:00

I have a XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <nametable> <namerow> <namecell

  • 0

I have a XML like this:

<?xml version="1.0" encoding="UTF-8"?>
<Section>
    <Chapter>
        <nametable>
            <namerow>
                <namecell stuff="1">
                    <entity>A</entity>
                </namecell>
                <namecell stuff="2">
                    <entity>B</entity>
                </namecell>
            </namerow>
        </nametable>
    </Chapter>
</Section>

My XSLT is like this:

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

<xsl:output method="text"/>

    <xsl:template match="/">
        <xsl:apply-templates select="Section/Chapter//nametable"/>
    </xsl:template>

    <xsl:template match="nametable">
        <xsl:for-each select="./namerow">
            <xsl:value-of select="./namecell/@stuff"/>
            <xsl:value-of select="./namecell" />
        </xsl:for-each>
    </xsl:template>

<xsl:template match="text()"/>

</xsl:stylesheet>

Odd is I’m getting an output in this order 1 2 A B, I thought I’m going to get 1 A 2 B.

Not sure why is that ?.

TIA,

John

  • 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-30T10:12:33+00:00Added an answer on May 30, 2026 at 10:12 am

    Your problem is here:

            <xsl:for-each select="./namerow">
                <xsl:value-of select="./namecell/@stuff"/>
                <xsl:value-of select="./namecell" />
            </xsl:for-each>
    

    Unlike in XSLT 1.0 in XSLT 2.0 the xsl:value-of instruction outputs all items of the sequence specified in its select attribute.

    This means that

    <xsl:value-of select="./namecell/@stuff"/>
    

    outputs all stuff attributes (1 and 2)

    then the next instruction:

               <xsl:value-of select="./namecell" />
    

    outputs the string value of the two namecell children — respectively "A" and "B".

    Solution:

    Replace:

            <xsl:for-each select="./namerow">
                <xsl:value-of select="./namecell/@stuff"/>
                <xsl:value-of select="./namecell" />
            </xsl:for-each>
    

    with:

            <xsl:for-each select="./namerow">
                <xsl:value-of select="./namecell/(@stuff|entity)"/>
            </xsl:for-each>
    

    The complete code with this modification is:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            version="2.0">
    
        <xsl:output method="text"/>
    
            <xsl:template match="/">
                <xsl:apply-templates select="Section/Chapter//nametable"/>
            </xsl:template>
    
            <xsl:template match="nametable">
                <xsl:for-each select="./namerow">
                    <xsl:value-of select="./namecell/(@stuff|entity)"/>
                </xsl:for-each>
            </xsl:template>
    
        <xsl:template match="text()"/>
    </xsl:stylesheet>
    

    and when this transformation is applied on the provided XML document:

    <Section>
        <Chapter>
            <nametable>
                <namerow>
                    <namecell stuff="1">
                        <entity>A</entity>
                    </namecell>
                    <namecell stuff="2">
                        <entity>B</entity>
                    </namecell>
                </namerow>
            </nametable>
        </Chapter>
    </Section>
    

    the wanted result is produced:

    1 A 2 B
    

    Second solution (probably what you intended to do in the first place):

    Replace:

        <xsl:template match="nametable">
            <xsl:for-each select="./namerow">
                <xsl:value-of select="./namecell/@stuff"/>
                <xsl:value-of select="./namecell" />
            </xsl:for-each>
        </xsl:template>
    

    with:

        <xsl:template match="nametable">
            <xsl:for-each select="namerow/namecell">
                <xsl:value-of select="@stuff"/>
                <xsl:value-of select="entity"/>
            </xsl:for-each>
        </xsl:template>
    

    Now you again get the wanted result:

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

Sidebar

Related Questions

I have an XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <Cell colname=1> <Value>A</Value>
I have an XML like this: <?xml version=1.0 encoding=UTF-8?> <Section> <Chapter> <Cell colname=1> <Value>A</Value>
I have XML-file with settings like this <?xml version=1.0 encoding=utf-8 ?> <configuration> <configSections> <sectionGroup
I have a xml like this: <?xml version=1.0 encoding=utf-8?> <assessment xmlns=http://xml.thinkcentral.com/pub/xml/hsp/assessment xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xhtml=http://www.w3.org/1999/xhtml xmlns:tia=http://xml.thinkcentral.com/pub/xml/hsp/tia
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
I have a simple XML file like so: <?xml version=1.0 encoding=UTF-8?> <foo attr=blah &#176;
I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8
I have the following sample nested XML <?xml version=1.0 encoding=UTF-8?> <text> <main> <div n=Section
My XML looks like this: <?xml version = 1.0 encoding = utf-8?> <gallery> <name>Rosie's

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.