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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:41:30+00:00 2026-06-08T08:41:30+00:00

[EDIT: Changed title to better conceptualize the question.] The value of the attribute @xml:space

  • 0

[EDIT: Changed title to better conceptualize the question.]

The value of the attribute @xml:space can be either "default" or "preserve". XML specifies what the second means but leaves the first up to the application. (I think I have that correct.) So what if the application wants default to implement XSchema’s collapse? How could XSLT 1.0 actually do this?

I think the built-in template for processing text, that is,

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

would need to be replaced with something like this pseudo-code:

<xsl:choose>
   <xsl:when test="../@xml:space='preserve'"
     <xsl:value-of select="."/>
   </xsl:when>
   <xsl:otherwise>

      if position(.)=1 then output LTRIM(value-of(.))
      if position(.)=last() then output RTRIM(value-of(.))
      if position(.)= 1 and last()=1 then output normalize-space(.)

   </xsl:otherwise>
</xsl:choose>

This input then:

<persName> The man is 
   <forename>Edward</forename>

   <forename>George</forename>
   <surname type="linked">Bulwer-Lytton</surname>, <roleName>Baron Lytton of
   <placeName>Knebworth</placeName>
   </roleName>
</persName>

would get rendered correctly as The man is Edward George Bulwer-Lytton, Baron Lytton of Knebworth with the space before The man and after Knebworth trimmed and the spaces between Edward and George collapsed. (The example is from TEI.)

[EDIT: I removed an incorrect and misleading paragraph here.]

The XSLT 1.0 to implement that pseudo-code would need to be executed for every text node. Wouldn’t that be ugly and slow? [EDIT: Or maybe not. I simplified the pseudo code. Are there fast trim routines? Is the choose really that slow?]

Bottom line: How does one implement XSchema’s collapse in XSLT 1.0 (with only browser-embedded extensions)?

I hope I’m saying all that correctly. And I hope the code is simple. I haven’t yet seen how it can be. [EDIT: Changed xs:collapse to XSchema’s collapse.]

  • 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-08T08:41:32+00:00Added an answer on June 8, 2026 at 8:41 am

    I checked at xml-dev, and it turns out I was correct about the meaning and intended use of @xml:space.

    Here is code to normalize whitespace in mixed-content elements (that’s a better way to say what I wanted to do):

    <xsl:template priority=".7" match="text()[position()=1 and not((ancestor::node()/@xml:space)[position()=last()]='preserve')]">
        <xsl:value-of select="normalize-space()"/>
        <xsl:if test="normalize-space(substring(., string-length(.))) = ''">
            <xsl:text> </xsl:text>
        </xsl:if>
    </xsl:template>
    <xsl:template priority=".7" match="text()[position()=last() and not((ancestor::node()/@xml:space)[position()=last()]='preserve')]">
        <xsl:if test="normalize-space(substring(., 1, 1)) = ''">
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="normalize-space()"/>
    </xsl:template>
    <xsl:template priority=".8" match="text()[position()=1 and position()=last() and not((ancestor::node()/@xml:space)[position()=last()]='preserve')]" >
        <xsl:value-of select="normalize-space(.)"/>
    </xsl:template>
    

    Filtering on @xml:space allows preserve to override. The test= is just a way to test for whitespace. The priorities resolve the conflict caused when a node is the only text node in an element, and thus both the first and the last.

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

Sidebar

Related Questions

(Someone edit the title if you can understand and define my problem better.) The
EDIT: I have changed the question as it was too localized and gained negative
Can we change the default action of the edit selected row button? Here is
Note: The title of this was changed to better reflect the actual problem. I've
[Apologies if my question title does not accurately describe my problem- if you can
[EDIT] original title of this question was Getting the last element of a Postgres
The question is in the title... I searched but couldn't find anything. Edit: I
EDIT: changed the title. I didn't know it at the time but this is
EDIT: Changed title to actually be correct I'm trying to simulate a modal popup
Edit: Changed the title. I'm less interested in the two segments being the same,

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.