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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:32:40+00:00 2026-05-22T03:32:40+00:00

I have a Sharepoint list which I want to convert to a JSON via

  • 0

I have a Sharepoint list which I want to convert to a JSON via an XSL dataview.

I have an XSL recursive replace function which I use to replace all special characters (escape backslash, double quotes to " etc) which gives me nice clean JSON which parses correctly in the users browser.

The final thing that I need to escape / replace is the new line char. The new line causes errors in parsing the JSON in some browsers.

Here is some xsl which tests if the contents of title has a new line char, if it does we output a paragraph:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

    <xsl:for-each select="catalog/cd">

        <xsl:if test='contains(title,"&#xA;")'>   
                <p>Found <xsl:value-of select="title" /></p>
        </xsl:if>

    </xsl:for-each>

</xsl:template>
</xsl:stylesheet>

Here is some sample xml:

<catalog>
    <cd>
        <title>Empire 
Burlesque</title>
        <artist>Bob Dylan</artist>
        <country>USA</country>
        <company>Columbia</company>
        <price>10.90</price>
        <year>1985</year>
    </cd>
    <cd>
        <title>Hide your heart</title>
        <artist>Bonnie Tyler</artist>
        <country>UK</country>
        <company>CBS Records</company>
        <price>9.90</price>
        <year>1988</year>
    </cd>
    <cd>
        <title>Greatest Hits</title>
        <artist>Dolly Parton</artist>
        <country>USA</country>
        <company>RCA</company>
        <price>9.90</price>
        <year>1982</year>
    </cd>
</catalog>

“Empire Burlesque” should be the only item to pass the test, but all three titles pass the if statement and are outputted.

EDIT

Modifying the solution below, I assume this should work if I wanted to do the search and replace on a individual node basis? I won’t be able to test it in Sharepoint until tomorrow.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
  <xsl:for-each select="catalog/cd">

  <xsl:variable name="title_clean">
    <xsl:call-template name="repNL">
      <xsl:with-param name="pText" select="title"/>
    </xsl:call-template>
  </xsl:variable>

  <p><xsl:value-of select='$title_clean' /></p>

  </xsl:for-each>
</xsl:template>


<xsl:template name="repNL">
  <xsl:param name="pText" select="."/>

  <xsl:copy-of select="substring-before(concat($pText,'&#xA;'),'&#xA;')"/>

  <xsl:if test="contains($pText, '&#xA;')">
  <br />
  <xsl:call-template name="repNL">
  <xsl:with-param name="pText" select=
  "substring-after($pText, '&#xA;')"/>
  </xsl:call-template>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>
  • 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-22T03:32:41+00:00Added an answer on May 22, 2026 at 3:32 am

    “Empire Burlesque” should be the only
    item to pass the test, but all three
    titles pass the if statement and are
    outputted.

    Cannot reproduce the alleged problem — tested with 9 different XSLT processors, including all from Microsoft.

    Anyway:

    This transformation replaces any NL character in a text node with a br element:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text()" name="repNL">
      <xsl:param name="pText" select="."/>
    
      <xsl:copy-of select=
      "substring-before(concat($pText,'&#xA;'),'&#xA;')"/>
    
      <xsl:if test="contains($pText, '&#xA;')">
       <br />
       <xsl:call-template name="repNL">
        <xsl:with-param name="pText" select=
        "substring-after($pText, '&#xA;')"/>
       </xsl:call-template>
      </xsl:if>
     </xsl:template>
    </xsl:stylesheet>
    

    when applied on the following XML document (the provided one with an added cd to make it more interesting):

    <catalog>
        <cd>
            <title>Line1
            Line2
            Line3
            </title>
            <artist>Bob Dylan</artist>
            <country>USA</country>
            <company>Columbia</company>
            <price>10.90</price>
            <year>1985</year>
        </cd>
        <cd>
            <title>Empire
            Burlesque</title>
            <artist>Bob Dylan</artist>
            <country>USA</country>
            <company>Columbia</company>
            <price>10.90</price>
            <year>1985</year>
        </cd>
        <cd>
            <title>Hide your heart</title>
            <artist>Bonnie Tyler</artist>
            <country>UK</country>
            <company>CBS Records</company>
            <price>9.90</price>
            <year>1988</year>
        </cd>
        <cd>
            <title>Greatest Hits</title>
            <artist>Dolly Parton</artist>
            <country>USA</country>
            <company>RCA</company>
            <price>9.90</price>
            <year>1982</year>
        </cd>
    </catalog>
    

    the wanted, correct result is produced:

    <catalog>
       <cd>
          <title>Line1<br/>     Line2<br/>      Line3<br/>      
          </title>
          <artist>Bob Dylan</artist>
          <country>USA</country>
          <company>Columbia</company>
          <price>10.90</price>
          <year>1985</year>
       </cd>
       <cd>
          <title>Empire<br/>        Burlesque</title>
          <artist>Bob Dylan</artist>
          <country>USA</country>
          <company>Columbia</company>
          <price>10.90</price>
          <year>1985</year>
       </cd>
       <cd>
          <title>Hide your heart</title>
          <artist>Bonnie Tyler</artist>
          <country>UK</country>
          <company>CBS Records</company>
          <price>9.90</price>
          <year>1988</year>
       </cd>
       <cd>
          <title>Greatest Hits</title>
          <artist>Dolly Parton</artist>
          <country>USA</country>
          <company>RCA</company>
          <price>9.90</price>
          <year>1982</year>
       </cd>
    </catalog>
    

    Explanation:

    1. The identity rule/template copies every node “as-is”.

    2. The overriding template that matches any text node (also named as “repNL”) prforms the following processing:

    3. Using a sentinel (a NL character appended to the string), the substring before the first NL character (or the complete string, if th no NL character is contained) is copied to the output.

    4. If a NL character is really contained, then a br element is generated and the template calls itself recursively for the remaining string after this NL character.

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

Sidebar

Related Questions

In my SharePoint List I have a custom field which is a filtered lookup.
I have a SharePoint List to which I'm adding new ListItems using the Client
I have a sharepoint list which has several fields. It seems that when a
I have a Sharepoint list which have columns like : CopmanyName, Add1, Add2 Country,
I have a SharePoint 2010 Task list which includes an Assigned To column of
I have a Sharepoint 2010 list which has a column of type Number how
Basically I have an InfoPath form which recieves some data from a SharePoint list,
I have a sharepoint event handler which I want to activate for a single
I have a sharepoint list which has some Lookup fields. When I iterate through
I have a SharePoint list that is populated via an InfoPath form. There are

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.