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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:25:26+00:00 2026-05-30T05:25:26+00:00

I have the following xslt to transform data into a JQuery-accepted format. However, because

  • 0

I have the following xslt to transform data into a JQuery-accepted format. However, because JSON doesn’t accept double quotes in the data string, I need to replace ” with an escape sequence \”

XML:

<?xml version="1.0" encoding="UTF-8"?>
<Rowsets>
    <Rowset>
        <Columns>
            <Column Description="Element_1" SQLDataType="12" />
            <Column Description="Element_2" SQLDataType="12" />
            <Column Description="Element_3" SQLDataType="93" />
        </Columns>
        <Row>
            <Element_1>test_data</Element_1>
            <Element_2>test_quo"te</Element_2>
            <Element_3>test_data</Element_3>
        </Row>
    </Rowset>
</Rowsets>

Current XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
    <xsl:output method="text" media-type="text/csv" encoding="UTF-8"/>
    <xsl:param name="RowDelim">],</xsl:param>
    <xsl:param name="RowLast">]</xsl:param>
    <xsl:param name="RowStart">[</xsl:param>
    <xsl:param name="startBracket">{ </xsl:param>
    <xsl:param name="JQTableData">"aaData": [</xsl:param>
    <xsl:param name="JQTableEnd">] }</xsl:param>
    <xsl:param name="FieldDelim">,</xsl:param>
    <xsl:param name="StringDelim">"</xsl:param>
    <xsl:param name="DateFormat">yyyy-MM-dd HH:mm:ss</xsl:param>


    <xsl:template match="/">





        <xsl:for-each select="Rowsets">

            <xsl:for-each select="Rowset">
            <xsl:value-of select="$startBracket"/>
            <xsl:value-of select="$JQTableData"/>
                <xsl:variable name="CurrentColumns" select="Columns"/>
                <xsl:for-each select="Columns">
                    <xsl:for-each select="Column">

                        <xsl:if test="not(position() = last())">

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

                </xsl:for-each>
                <xsl:for-each select="Row">
                <xsl:value-of select="$RowStart"/>
                    <xsl:for-each select="*">
                        <xsl:variable name="ColName">
                            <xsl:value-of select="name(.)"/>
                        </xsl:variable>
                        <xsl:variable name="ColType">
                            <xsl:value-of select="$CurrentColumns/Column[@Name=$ColName]/@SQLDataType"/>
                        </xsl:variable>
                        <xsl:choose>
                            <xsl:when test="$ColType= '2' or $ColType= '3' or $ColType= '4' or $ColType= '5' or 

$ColType= '6' or $ColType= '7' or $ColType= '8' or $ColType= '-7'">
                                <xsl:value-of select="."/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$StringDelim"/>
                                <xsl:choose>
                                    <xsl:when test="$ColType= '91' or $ColType= '92' or $ColType= '93'">
                                        <xsl:choose>
                                            <xsl:when test=". = 'TimeUnavailable'">
                                                <xsl:value-of select="."/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                                                        </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:when>
                                    <xsl:otherwise>
                                    <xsl:choose>
                                        <xsl:when test=". = 'true'">
                                            <xsl:text>Y</xsl:text>
                                        </xsl:when>
                                        <xsl:when test=". = 'false'">
                                            <xsl:text>N</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="."/>
                                        </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <xsl:value-of select="$StringDelim"/>
                            </xsl:otherwise>
                        </xsl:choose>
                        <xsl:if test="not(position() = last())">
                            <xsl:value-of select="$FieldDelim"/>
                        </xsl:if>
                    </xsl:for-each>
                            <xsl:if test="not(position() = last())">
                            <xsl:value-of select="$RowDelim"/>
                        </xsl:if>
                            <xsl:if test="position() = last()">
                            <xsl:value-of select="$RowLast"/>
                        </xsl:if>

                </xsl:for-each>
                <xsl:value-of select="$JQTableEnd"/>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>



</xsl:stylesheet>

Current output:

{ "aaData": [["test_data","test_quo"te","test_data"]] }

Desired output:

{ "aaData": [["test_data","test_quo\"te","test_data"]] }
  • 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-30T05:25:27+00:00Added an answer on May 30, 2026 at 5:25 am

    Add this template to your code:

        <xsl:template name="escapeQuote">
          <xsl:param name="pText" select="."/>
    
          <xsl:if test="string-length($pText) >0">
           <xsl:value-of select=
            "substring-before(concat($pText, '&quot;'), '&quot;')"/>
    
           <xsl:if test="contains($pText, '&quot;')">
            <xsl:text>\"</xsl:text>
    
            <xsl:call-template name="escapeQuote">
              <xsl:with-param name="pText" select=
              "substring-after($pText, '&quot;')"/>
            </xsl:call-template>
           </xsl:if>
          </xsl:if>
        </xsl:template>
    

    Then change:

    <xsl:value-of select="."/>
    

    to:

    <xsl:call-template name="escapeQuote"/>
    

    Your complete transformation now becomes:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
            <xsl:output method="text" media-type="text/csv" encoding="UTF-8"/>
            <xsl:param name="RowDelim">],</xsl:param>
            <xsl:param name="RowLast">]</xsl:param>
            <xsl:param name="RowStart">[</xsl:param>
            <xsl:param name="startBracket">{ </xsl:param>
            <xsl:param name="JQTableData">"aaData": [</xsl:param>
            <xsl:param name="JQTableEnd">] }</xsl:param>
            <xsl:param name="FieldDelim">,</xsl:param>
            <xsl:param name="StringDelim">"</xsl:param>
            <xsl:param name="DateFormat">yyyy-MM-dd HH:mm:ss</xsl:param>
    
    
            <xsl:template match="/">
    
                <xsl:for-each select="Rowsets">
    
                    <xsl:for-each select="Rowset">
                    <xsl:value-of select="$startBracket"/>
                    <xsl:value-of select="$JQTableData"/>
                        <xsl:variable name="CurrentColumns" select="Columns"/>
                        <xsl:for-each select="Columns">
                            <xsl:for-each select="Column">
    
                                <xsl:if test="not(position() = last())">
    
                                </xsl:if>
                            </xsl:for-each>
    
                        </xsl:for-each>
                        <xsl:for-each select="Row">
                        <xsl:value-of select="$RowStart"/>
                            <xsl:for-each select="*">
                                <xsl:variable name="ColName">
                                    <xsl:value-of select="name(.)"/>
                                </xsl:variable>
                                <xsl:variable name="ColType">
                                    <xsl:value-of select="$CurrentColumns/Column[@Name=$ColName]/@SQLDataType"/>
                                </xsl:variable>
                                <xsl:choose>
                                    <xsl:when test="$ColType= '2' or $ColType= '3' or $ColType= '4' or $ColType= '5' or
    
        $ColType= '6' or $ColType= '7' or $ColType= '8' or $ColType= '-7'">
                                        <xsl:value-of select="."/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="$StringDelim"/>
                                        <xsl:choose>
                                            <xsl:when test="$ColType= '91' or $ColType= '92' or $ColType= '93'">
                                                <xsl:choose>
                                                    <xsl:when test=". = 'TimeUnavailable'">
                                                        <xsl:value-of select="."/>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                                                                </xsl:otherwise>
                                                </xsl:choose>
                                            </xsl:when>
                                            <xsl:otherwise>
                                            <xsl:choose>
                                                <xsl:when test=". = 'true'">
                                                    <xsl:text>Y</xsl:text>
                                                </xsl:when>
                                                <xsl:when test=". = 'false'">
                                                    <xsl:text>N</xsl:text>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                  <xsl:call-template name="escapeQuote"/>
                                                    <!-- <xsl:value-of select="."/> -->
                                                </xsl:otherwise>
                                                </xsl:choose>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                        <xsl:value-of select="$StringDelim"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                                <xsl:if test="not(position() = last())">
                                    <xsl:value-of select="$FieldDelim"/>
                                </xsl:if>
                            </xsl:for-each>
                                    <xsl:if test="not(position() = last())">
                                    <xsl:value-of select="$RowDelim"/>
                                </xsl:if>
                                    <xsl:if test="position() = last()">
                                    <xsl:value-of select="$RowLast"/>
                                </xsl:if>
    
                        </xsl:for-each>
                        <xsl:value-of select="$JQTableEnd"/>
                    </xsl:for-each>
                </xsl:for-each>
            </xsl:template>
    
            <xsl:template name="escapeQuote">
              <xsl:param name="pText" select="."/>
    
              <xsl:if test="string-length($pText) >0">
               <xsl:value-of select=
                "substring-before(concat($pText, '&quot;'), '&quot;')"/>
    
               <xsl:if test="contains($pText, '&quot;')">
                <xsl:text>\"</xsl:text>
    
                <xsl:call-template name="escapeQuote">
                  <xsl:with-param name="pText" select=
                  "substring-after($pText, '&quot;')"/>
                </xsl:call-template>
               </xsl:if>
              </xsl:if>
            </xsl:template>
    
    </xsl:stylesheet>
    

    when this transformation is applied on the provided XML document:

    <Rowsets>
        <Rowset>
            <Columns>
                <Column Description="Element_1" SQLDataType="12" />
                <Column Description="Element_2" SQLDataType="12" />
                <Column Description="Element_3" SQLDataType="93" />
            </Columns>
            <Row>
                <Element_1>test_data</Element_1>
                <Element_2>test_quo"te</Element_2>
                <Element_3>test_data</Element_3>
            </Row>
        </Rowset>
    </Rowsets>
    

    the wanted, correct result is produced:

    { "aaData": [["test_data","test_quo\"te","test_data"]] }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following line of xml that I'm trying transform using XSLT but
I have the following in xslt <?xml version=1.0 encoding=UTF-8?> <xsl:stylesheet version=2.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:fn=http://www.w3.org/2005/02/xpath-functions
I have the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:my=my_namespace> <xsl:template match=/> <xsl:value-of select=document('')/xsl:stylesheet/namespace::my/> </xsl:template>
I have the following xml <AAA> <BBB>Total</BBB> </AAA> Transforming it with the following xslt
I have the following code block in my xslt; <xsl:when test=StatusData/Status/Temperature > 27> <td
I have the following situation: There is a tool that gets an XSLT from
Is it possible to merge elements using XSLT. If I have the following XML
Lets say I have a xslt stylesheet like the following: <?xml version=1.0 encoding=utf-8?> <xsl:stylesheet
i have the following xslt sheet: <?xml version=1.0 encoding=UTF-8 ?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform version=1.0> <xsl:variable
I have the following XSLT code that almost does what I want: <xsl:variable name=scoredItems

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.