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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:00:37+00:00 2026-06-04T06:00:37+00:00

In my XSLT transformation I have two analyze-strings that I need to use to

  • 0

In my XSLT transformation I have two analyze-strings that I need to use to process one node. They work fine one by one, but I don’t know how to put them together.

XML document looks like this:

<article>
    <title>Article 1</title>
    <text><![CDATA[Lorem ipsum dolor sit amet, s consectetur adipiscing elit. Donec lorem diam, eleifend sed mollis id, condimentum in velit.

Sed sit amet erat ac mauris adipiscing elementum. Pellentesque eget quam augue, id faucibus magna.

Ut malesuada arcu eu elit sodales sodales. Morbi tristique porttitor tristique. Praesent eget vulputate dui. Cras ut tortor massa, at faucibus ligula.]]></text>
</article>

Here’s my XSLT:

<xsl:template match="/">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>Page title</title>
        </head>
        <body>
            <xsl:for-each select="article">
                <h1><xsl:value-of select="./title"/></h1>

                <!-- This adds paragraphs tags instead of empty lines in the text -->
                <xsl:analyze-string select="./text" regex="&#xa;">
                    <xsl:non-matching-substring>
                        <p>
                            <xsl:value-of select="." disable-output-escaping="yes"/>
                        </p>
                    </xsl:non-matching-substring>
                </xsl:analyze-string> 

                <!-- This is Czech language specific. It looks for ' s ' (or other letter) and changes second space for &nbsp;. So after that it is ' s&nbsp;'. -->
                <xsl:analyze-string select="./text" regex="(\s[k/K/s/S/v/V/z/Z]\s)">
                    <xsl:matching-substring>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="replace(., ' ','')" disable-output-escaping="yes"/>
                        <xsl:text disable-output-escaping="yes"><![CDATA[&nbsp;]]></xsl:text>
                    </xsl:matching-substring>
                    <xsl:non-matching-substring>
                        <xsl:value-of select="." disable-output-escaping="yes"/>
                    </xsl:non-matching-substring>
                </xsl:analyze-string>
            </xsl:for-each>
        </body>
    </html>
</xsl:template>

I need to apply both analyze-strings on the generated text so there are <p> tags for paragraphs and also added &nbsp; on the right places.

My desired output would look like this:

<h1>Article 1</h1>    
<p>Lorem ipsum dolor sit amet, s&nbsp;consectetur adipiscing elit. Donec lorem diam, eleifend sed mollis id, condimentum in velit.</p>
<p>Sed sit amet erat ac mauris adipiscing elementum. Pellentesque eget quam augue, id faucibus magna.</p>
<p>Ut malesuada arcu eu elit sodales sodales. Morbi tristique porttitor tristique. Praesent eget vulputate dui. Cras ut tortor massa, at faucibus ligula.</p>

Any idea how to do this? Thank you for taking your time and trying to help me.

  • 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-04T06:00:39+00:00Added an answer on June 4, 2026 at 6:00 am

    Here is my tweak on Dimitre’s solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output method="html" indent="yes" encoding="UTF-8"/>
    
     <xsl:template match="/*/text">
       <xsl:for-each select="tokenize( replace(., '\s([kKsSvVzZ])\s', ' $1&#xA0;'), '\n')">
         <p><xsl:value-of select="."/></p>
      </xsl:for-each>
     </xsl:template>
    
     <xsl:template match="title">
      <h1><xsl:value-of select="."/></h1>
     </xsl:template>
    </xsl:stylesheet>
    

    Notes

    1. I am not sure what you mean by “the letters s/S/v/V/k/K/z/Z”. This is not valid regex. You need to clarify. I have taken a guess that you meant the character class [sSvVkKzZ]
    2. Although not clear, the reference to the Czech language suggests that UTF-8 might be a better choice for output encoding rather than ASCII.
    3. Although not clear, the expected output tags, suggest a more appropriate serialization would be html.
    4. As a side benefit of choosing html serialization, we no longer need the character map, making our solution simpler. We can leverage the in-built character map for html serialization.
    5. Use of fn:tokenise() obviates the need for xsl:analyze-string/xsl:non-matching-substring nodes, arguably resulting in a tighter solution.
    6. This solution was tested with Saxon.
    7. Variations are possible. For example you could move the replace() invocation to inside the xsl:value-of, which you may regard as more read-able.
    8. The disadvantage of my solution is that it does not work with disable-output-escaping=”yes” . However I suggest that if you think you need this, please look again strongly at why. Any HTML needs HTML-safe encoding unless it is inside a CDATA section. There is something not right with the idea of generating HTML with disable-output-escaping turned on. Perhaps I have not fully understood the question. Could you give a Use Case which clarifies the point?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xslt transformation that works fine when run in Altova XML Spy,
The problem is, that my XSLT-Transformation process ( called by .NET ), doesn't leave
For each agency node I need to find the stmt elements that have the
I'm working on a XSLT transformation that consists on merging two XML and then
After an XSLT transformation I keep getting leading question marks that (seem to) have
I have a trouble getting the following result from a xml/xslt transformation: <root> <node>
I need to have XSLT for the input below. The objective of this transformation
I have a simple web-app in which I use struts and xslt transformation. In
I have written a C# code for triggering an XML to XML (XSLT) transformation.
I am writing an XSLT transformation in which I wish to use the Replace

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.