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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:42:20+00:00 2026-05-19T05:42:20+00:00

I have a function that adds a zero-width characters. It’s not quite working the

  • 0

I have a function that adds a zero-width characters. It’s not quite working the way I want it to though. How do I get it to add the zero-space character every 15 chars only if it does not contain a normal space?

<xsl:template match="text()[parent::d:entry]">
    <xsl:call-template name="intersperse-with-zero-spaces">
        <xsl:with-param name="str" select="."/>
        <xsl:with-param name="max_length" select="number(15)"/>
    </xsl:call-template>
</xsl:template>
<xsl:template name="intersperse-with-zero-spaces">
        <xsl:param name="str"/>
        <xsl:param name="max_length"/>
        <xsl:variable name="ret">
            <xsl:value-of select="substring($str, 1, $max_length)"/>
            <xsl:if test="string-length($str) &gt; $max_length">
                <xsl:value-of select="'&#x200b;'"/>
                <xsl:call-template name="intersperse-with-zero-spaces">
                    <xsl:with-param name="str" select="substring($str, $max_length + 1)"/>
                    <xsl:with-param name="max_length" select="$max_length"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:variable>
        <xsl:value-of select="$ret"/>
    </xsl:template>
  • 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-19T05:42:21+00:00Added an answer on May 19, 2026 at 5:42 am

    A few hints. First off:

    <xsl:template match="d:entry/text()">
    

    is better than

    <xsl:template match="text()[parent::d:entry]">
    

    And then:

    <xsl:template name="intersperse-with-zero-spaces">
      <xsl:param name="str"/>
      <xsl:param name="max_length"/>
    
      <!-- your variable "ret" is not necessary at all -->
    
      <xsl:variable name="head" select="substring($str, 1, $max_length)" />
      <xsl:variable name="tail" select="substring($str, $max_length + 1)" />
    
      <xsl:value-of select="$head"/>
    
      <!-- the empty string evaluates to false -->
      <xsl:if test="$tail">
        <!-- there's no space present when translate() returns the same string
             and the $tail does not begin with a space, either  -->
        <xsl:if test="
          string-length(translate($head, ' ', '')) = string-length($head)
          and not(substring($tail, 1, 1) = ' ')
        ">
          <xsl:text>&#x200b;</xsl:text>
        </xsl:if>
        <xsl:call-template name="intersperse-with-zero-spaces">
          <xsl:with-param name="str"        select="$tail"/>
          <xsl:with-param name="max_length" select="$max_length"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:template>
    

    Also, I’d probably call the variable $interval, not $max_length. But that’s purely cosmetic.

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

Sidebar

Related Questions

I have a javascript function that manipulates the DOM when it is called (adds
I have a function that is effectively a replacement for print, and I want
I have a function that checks if a cookie (by name) exists or not:
I have a function that adds eventhandlers to control events. Right now I have
I have this function: /** * Helper function that adds the values of b
I have a function that adds shopping cart data to an array of arrays.
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that takes, amongst others, a parameter declared as int privateCount
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)

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.