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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:21:11+00:00 2026-05-22T00:21:11+00:00

I hope my title does justice for the question. Please consider the following block

  • 0

I hope my title does justice for the question. Please consider the following block of XML and sample block of XSL.

<root>
<level_one>
My first line of text on level_one
<level_two>
My only line of text on level_two
</level_two>
My second line of text on level_one
</level_one>
</root>

<xsl:template match="level_one">
<xsl:value-of select="text()"/>
<br/>
<xsl:apply-templates select="level_two"/>
</xsl:template>

<xsl:template match="level_two">
<xsl:value-of select="text()"/>
<br/>
</xsl:template>

As it stands, the output (modified here for reading) when executing the above is

My first line of text on level_one
<br/>
My only line of text on level_two
<br/>

I’m missing the second line of text on level_one. So I’m wondering two things.

  1. Is the XML valid? From what I know, the answwer is yes, but am I wrong?
  2. How can I modify the XSL in order to get the second line (or even more lines in my case than I’ve shown)?

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-05-22T00:21:12+00:00Added an answer on May 22, 2026 at 12:21 am

    Is the XML valid? From what I know,
    the answwer is yes, but am I wrong?

    Yes your XML is valid. Also, contrary to a comment above, there is nothing wrong with having mixed content (text and elements mixed together) in XML. It all depends on context and how the XML is used. For example, it would be almost impossible to author technical manuals without mixed content. (A good example is reference elements mixed with text in paragraph elements.)

    How can I modify the XSL in order to
    get the second line (or even more
    lines in my case than I’ve shown)?

    I’m not sure exactly what you’re trying to accomplish, but the reason you’re not seeing the second line of text is because you’re only matching the first line with the first <xsl:value-of select="text()"/>.

    I’m not sure if this would work on your full set of XML data, but you could replace both level_one and level_two templates with one template that matches all text():

      <xsl:template match="text()">
        <xsl:value-of select="."/>
        <br/>
      </xsl:template>
    

    This produces the following output:

      My first line of text on level_one
      <br/>
      My only line of text on level_two
      <br/>
      My second line of text on level_one
      <br/>
    

    You could also narrow the match down by specifying the level_one and level_two parents:

      <xsl:template match="level_one/text()|level_two/text()">
        <xsl:value-of select="."/>
        <br/>
      </xsl:template>
    

    This produces the exact same output, but leaves any other text open for matching in other templates.

    Hope this helps.

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

Sidebar

Related Questions

I hope the title and following text are clear, I'm not very familiar with
(I hope this is a valid question) As I stated in my title, I'm
I hope I worded the title of my question appropriately. In c# I can
First question on stackoverflow :) Hope I won't embarrass myself... I have a javascript
I hope the title of this question is somewhat clear, I couldn't figure out
Hope my title is not too confusing. Please let me know if there is
I hope the title makes sense. I have a set of items that I
(I hope my title is comprehensible, it was hard to sum up.) I have
I hope the title was good enough to help explain what I am having
since my title is buzzword compliant I hope I will get lots of answers

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.