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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:20:22+00:00 2026-05-30T04:20:22+00:00

I have an XML document of the following kind: <item> <item> <item> … (same

  • 0

I have an XML document of the following kind:

<item>
  <item>
    <item>
     ... (same elements <item> ... </item> here) 
    </item>
  </item>
</item>

… and the following XSL-transform:

<xsl:template match="item"><xsl:text>
open</xsl:text>
 <xsl:apply-templates/><xsl:text>
close</xsl:text>
</xsl:template>

What I obtain is:

open
open
open
close
close
close

So I wonder whether it is possible to somehow get an output with indents like this:

open
   open
      open
      close
   close
close

Thanks for your help!

P.S. It should be definitely possible to obtain what I want to by letting output method of the transformation to be HTML. However, I need to make indents “directly” in the text, not using any kind of HTML’s lists etc.

  • 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-30T04:20:24+00:00Added an answer on May 30, 2026 at 4:20 am

    This transformation:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="text"/>
    
     <xsl:template match="item">
      <xsl:param name="pIndent" select="'  '"/>
    
      <xsl:value-of select="concat('&#xA;', $pIndent, 'open')"/>
    
      <xsl:apply-templates>
       <xsl:with-param name="pIndent"
            select="concat($pIndent, '  ')"/>
      </xsl:apply-templates>
    
      <xsl:value-of select="concat('&#xA;', $pIndent, 'close')"/>
     </xsl:template>
    
     <xsl:template match="node()[not(self::item)]">
      <xsl:apply-templates/>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the provided XML document:

    <item>
        <item>
            <item>      ...
                <item> ... </item>
            </item>
        </item>
    </item>
    

    produces the wanted, indented output:

      open
        open
          open
            open
            close
          close
        close
      close
    

    Explanation:

    The $pIndent parameter is used to hold the string of whitespace to be prepended to the non-white space output. Whenever an xsl:apply-templates is used, the value passed with this parameter is expanded by two spaces.

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

Sidebar

Related Questions

Picture the following situation. I have an XML document as follows, <Form> <Control Type=Text
I have a xml document on the following format and want to transform it
I have the following XML document: <x> <a>Some text</c> <b>Some text 2</b> <c>Some text
I have an xml document like the following: <menuitem navigateurl=/PressCentre/ text=&#1087;&#1088;&#1077;&#1089; &#1094;&#1077;&#1085;&#1090;&#1098;&#1088;> <menuitem navigateurl=/PressCentre/RegisterForPressAlerts/
I have an xml document with the following structure: <?xml version=1.0 encoding=UTF-8?> <items> <item>
I have the following XML document: <?xml version=1.0 encoding=UTF-8?> <cars> <car body=Wagon> <text>Red</text> </car>
Suppose I have the following XML Document. <reply success=true>More nodes go here</reply> How to
I have an XML document which contains the following example extract: <p> Some text
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following xml document, I need an xquery expression to know how

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.