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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:18:12+00:00 2026-05-10T19:18:12+00:00

I’m trying to convert an XML file into the markup used by dokuwiki, using

  • 0

I’m trying to convert an XML file into the markup used by dokuwiki, using XSLT. This actually works to some degree, but the indentation in the XSL file is getting inserted into the results. At the moment, I have two choices: abandon this XSLT thing entirely, and find another way to convert from XML to dokuwiki markup, or delete about 95% of the whitespace from the XSL file, making it nigh-unreadable and a maintenance nightmare.

Is there some way to keep the indentation in the XSL file without passing all that whitespace on to the final document?

Background: I’m migrating an autodoc tool from static HTML pages over to dokuwiki, so the API developed by the server team can be further documented by the applications team whenever the apps team runs into poorly-documented code. The logic is to have a section of each page set aside for the autodoc tool, and to allow comments anywhere outside this block. I’m using XSLT because we already have the XSL file to convert from XML to XHTML, and I’m assuming it will be faster to rewrite the XSL than to roll my own solution from scratch.

Edit: Ah, right, foolish me, I neglected the indent attribute. (Other background note: I am new to XSLT.) On the other hand, I still have to deal with newlines. Dokuwiki uses pipes to differentiate between table columns, which means that all of the data in a table line must be on one line. Is there a way to suppress newlines being outputted (just occasionally), so I can do some fairly complex logic for each table cell in a somewhat readable fasion?

  • 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. 2026-05-10T19:18:12+00:00Added an answer on May 10, 2026 at 7:18 pm

    There are three reasons for getting unwanted whitespace in the result of an XSLT transformation:

    1. whitespace that comes from between nodes in the source document
    2. whitespace that comes from within nodes in the source document
    3. whitespace that comes from the stylesheet

    I’m going to talk about all three because it can be hard to tell where whitespace comes from so you might need to use several strategies.

    To address the whitespace that is between nodes in your source document, you should use <xsl:strip-space> to strip out any whitespace that appears between two nodes, and then use <xsl:preserve-space> to preserve the significant whitespace that might appear within mixed content. For example, if your source document looks like:

    <ul>   <li>This is an <strong>important</strong> <em>point</em></li> </ul> 

    then you will want to ignore the whitespace between the <ul> and the <li> and between the </li> and the </ul>, which is not significant, but preserve the whitespace between the <strong> and <em> elements, which is significant (otherwise you’d get ‘This is an **important***point*’). To do this use

    <xsl:strip-space elements='*' /> <xsl:preserve-space elements='li' /> 

    The elements attribute on <xsl:preserve-space> should basically list all the elements in your document that have mixed content.

    Aside: using <xsl:strip-space> also reduces the size of the source tree in memory, and makes your stylesheet more efficient, so it’s worth doing even if you don’t have whitespace problems of this sort.

    To address the whitespace that appears within nodes in your source document, you should use normalize-space(). For example, if you have:

    <dt>   a definition </dt> 

    and you can be sure that the <dt> element won’t hold any elements that you want to do something with, then you can do:

    <xsl:template match='dt'>   ...   <xsl:value-of select='normalize-space(.)' />   ... </xsl:template> 

    The leading and trailing whitespace will be stripped from the value of the <dt> element and you will just get the string 'a definition'.

    To address whitespace coming from the stylesheet, which is perhaps the one you’re experiencing, is when you have text within a template like this:

    <xsl:template match='name'>   Name:   <xsl:value-of select='.' /> </xsl:template> 

    XSLT stylesheets are parsed in the same way as the source documents that they process, so the above XSLT is interpreted as a tree that holds an <xsl:template> element with a match attribute whose first child is a text node and whose second child is a <xsl:value-of> element with a select attribute. The text node has leading and trailing whitespace (including line breaks); since it’s literal text in the stylesheet, it gets literally copied over into the result, with all the leading and trailing whitespace.

    But some whitespace in XSLT stylesheets get stripped automatically, namely those between nodes. You don’t get a line break in your result because there’s a line break between the <xsl:value-of> and the close of the <xsl:template>.

    To get only the text you want in the result, use the <xsl:text> element like this:

    <xsl:template match='name'>   <xsl:text>Name: </xsl:text>   <xsl:value-of select='.' /> </xsl:template> 

    The XSLT processor will ignore the line breaks and indentation that appear between nodes, and only output the text within the <xsl:text> element.

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

Sidebar

Ask A Question

Stats

  • Questions 158k
  • Answers 158k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's a few layers which you can simulate this at.… May 12, 2026 at 11:15 am
  • Editorial Team
    Editorial Team added an answer $(this).prev("div") or $(this).prev() or $(this).prev(".resumehint") you can replace $(this) with… May 12, 2026 at 11:15 am
  • Editorial Team
    Editorial Team added an answer Stick this in the tester script right before the import… May 12, 2026 at 11:15 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.