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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:39:11+00:00 2026-06-15T22:39:11+00:00

I have an xml document with the below structure. I’m writing a transformation where

  • 0

I have an xml document with the below structure. I’m writing a transformation where I’d like to output the text from node B but ignore the element C and text node “title”. Essentially I’d like to extract the text “text goes here” and output it in a new element with all the whitespace normalised. Can anybody help? The below is what I’ve tried so far.

Input Doc
<A>
  <B>
    <C>title</C>
     text goes here
  </B>
</A>

Required output doc
<d>text goes here</d>


Solution A:
<xsl:template match="B">
  <d>       
    <xsl:copy-of select="./text()"/>                
  </d>
</xsl:template>

Problem: the whitespace between elements is preserved so I get something like this:

<d>

  Text goes here

</d>

I also tried using a value-of statement (<xsl:value-of select="./text()"/>) in the template in solution A but this didn’t return any text at all. Is there something wrong with the statement?

I should mention that I have overridden the the default text handling template using the following: <xsl:template match="text()" />

Thanks

  • 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-15T22:39:12+00:00Added an answer on June 15, 2026 at 10:39 pm

    The reason <xsl:value-of select="./text()"/> returned “nothing” is that ./text() will return a node set consisting of all the immediate child text nodes of the current node. The value-of a node set is the string value of its first item, which in this case is the whitespace-only text node between the opening <B> and the opening <C> tags. The same applies to the next-most-obvious normalize-space(text()) because that again converts the node set to a string (the first node value) and then normalizes space in that string. Instead, you need to normalize each child text node individually:

    <d>
      <xsl:for-each select="text()">
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:for-each>
    </d>
    

    One thing to note about this though is that if you have input like

    <A>
      <B>
        <C>title</C>
         text goes here
        <C>subtitle</C>
         more text here
      </B>
    </A>
    

    then you will get output of

    <d>text goes heremore text here</d>
    

    with no space between the bits either side of the subtitle. If this is a problem you can use a trick like

    <d>
      <xsl:for-each select="text()[normalize-space(.)]">
        <xsl:if test="position() &gt; 1"><xsl:text> </xsl:text></xsl:if>
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:for-each>
    </d>
    

    to iterate over only those text node children that contain non-whitespace characters, and add a space before all but the first of them.

    <d>text goes here more text here</d>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a document that it's structure is like below. There are a lot
I have an XML document generated from an external application, but that application does
I have a XML document like shown below: <root> <level1> <level2> <level3> ..... </level3>
I have an xml document like the below one that I am trying to
I have xml document like below, <chapter xmlns:xi=http://www.w3.org/2001/XInclude xml:id=chapter1> <title>First chapter</title> <section xml:id=section1> <imageobject>
I have an xml document that looks something like below (resources.xml), with a corresponding
I Have a XML document like below. i need to get record count for
I have some xml XML Document with duplicate tag names like below :: <ROOT>
I have an XML document containing contact information as seen below: <contact type=individual> <firstname>Some</firstname>
I have following CDATA inside xml document: <![CDATA[ <p xmlns=>Refer to the below: <br/>

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.