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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:48:02+00:00 2026-06-11T21:48:02+00:00

I have an Xml file: <?xml version=1.0 encoding=utf-8 ?> <root> <child> <gc>gc1Value</gc> </child> <child>child2Value</child>

  • 0

I have an Xml file:

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <child>
    <gc>gc1Value</gc>
  </child>
  <child>child2Value</child>
  <child>
    <gc>gc2Value</gc>
    <gc>gc3Value</gc>
    <gc>
      <ggc>ggcValue</ggc>
      <ggc>ggcValue</ggc>
    </gc>
  </child>
</root>

and an Xslt file:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
      <root>
      <xsl:for-each select="root/child">
        <xsl:if test=".!=''">
          <value>
            <xsl:value-of select="."/>
          </value>
        </xsl:if>
        <xsl:for-each select="root/child/gc">
          <xsl:if test=".!=''">
            <value>
              <xsl:value-of select="."/>
            </value>
          </xsl:if>
          <xsl:for-each select="root/child/gc/ggc">
            <xsl:if test=".!=''">
              <value>
                <xsl:value-of select="."/>
              </value>
            </xsl:if>
          </xsl:for-each>
        </xsl:for-each>
      </xsl:for-each>
      </root>
    </xsl:template>
</xsl:stylesheet>

I’m expecting to see this kind of result:

<root>
  <value>gc1Value</value>
  <value>child2Value</value>
  <value>gc2Value</value>
  <value>gc3Value</value>
  <value>ggcValue</value>
  <value>ggcValue</value>
</root>

but I’m getting this result:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <value>
    gc1Value
  </value>
  <value>child2Value</value>
  <value>
    gc2Value
    gc3Value

      ggcValue
      ggcValue

  </value>
</root>

I thought that by using . for the select this would only select the current node’s value, but it appears to be getting the values from the children as well. What should I do instead?

  • 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-11T21:48:03+00:00Added an answer on June 11, 2026 at 9:48 pm

    The problem is in here:

        <xsl:if test="gc!=''">
          <value>
            <xsl:value-of select="."/>
          </value>
        </xsl:if>
    

    “.” will get the current node and all its children.

    Use node::text() [ ie. select=”text()” ] if you only want the text. Also I would advise using ‘string-length(node) != 0’ and the likes instead of ”,

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

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>
I have a XML file, like this: <?xml version=1.0 encoding=utf-8 ?> <ROOT> <NAME> ItemName
I have an xml document: <?xml version=1.0 encoding=utf-8?> <Root> <Child name=MyType compareMode=EQ></Child> </Root> And
I have an xml file like this, <?xml version=1.0 encoding=utf-8 ?> <root> <FeaturedProductCategories> <FeaturedProductCategory>
So say I have this XML file: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root> <Category Name=Tasties>
I have the following xml file: <?xml version=1.0 encoding=utf-8?> <root> <phrase id=test><![CDATA[test]]></phrase> <phrase id=test0><![CDATA[test0]]></phrase>
I have an XML file of the following structure: <?xml version=1.0 encoding=utf-8?> <root> <ArrayOfLocationDTO
I have an xml file which i create myself. <?xml version='1.0' encoding='utf-8' ?> <Root>
I have an xml document like this: <?xml version=1.0 encoding=UTF-8?> <foo:root xmlns:foo=http://abc.com# xmlns:bar=http://def.com xmlns:ex=http://ex.com>

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.