?
Solved

XSLT removes CDATA Tags

Posted on 2005-03-07
3
Medium Priority
?
2,038 Views
Last Modified: 2013-11-19
Hi

I have an output file of XML which looks like

<CR><CR_NAME><![CDATA["INT-Afghanistan"]]></CR_NAME><CR_SRC><![CDATA[" 98289383"]]></CR_SRC><CR_SRCLEN><![CDATA[" "]]></CR_SRCLEN><CR_SRCPREFIX><![CDATA[" "]]></CR_SRCPREFIX><CR_DEST><![CDATA["93"]]></CR_DEST><CR_DESTLEN><![CDATA[" "]]></CR_DESTLEN><CR_PREFIX><![CDATA["93"]]></CR_PREFIX><CR_FLAGS><![CDATA["32"]]></CR_FLAGS><CR_CPNAME><![CDATA[" "]]></CR_CPNAME><CR_TRNAME><![CDATA[" "]]></CR_TRNAME><MTIME><![CDATA["2222222222"]]></MTIME></CR>

Using the XSLT pasted at the bottom script it formats the file to look like
      <CR>
            <CR_NAME> "INT-Afghanistan" </CR_NAME>
            <CR_SRC> "98289383" </CR_SRC>
            <CR_SRCLEN> "0" </CR_SRCLEN>
            <CR_SRCPREFIX> "98289383" </CR_SRCPREFIX>
            <CR_DEST> "" </CR_DEST>
            <CR_DESTLEN> "0" </CR_DESTLEN>
            <CR_PREFIX> "" </CR_PREFIX>
            <CR_FLAGS> "16" </CR_FLAGS>
            <CR_CPNAME> "" </CR_CPNAME>
            <CR_TRNAME> "" </CR_TRNAME>
      </CR>

What I need is for it to output like

<CR>
            <CR_NAME><![CDATA["INT-Afghanistan"]]></CR_NAME>
            <CR_SRC><![CDATA[" "]]></CR_SRC>
            <CR_SRCLEN><![CDATA[" "]]></CR_SRCLEN>
            <CR_SRCPREFIX><![CDATA[" "]]></CR_SRCPREFIX>
            <CR_DEST><![CDATA["93"]]></CR_DEST>
            <CR_DESTLEN><![CDATA[" "]]></CR_DESTLEN>
            <CR_PREFIX><![CDATA["93"]]></CR_PREFIX>
            <CR_FLAGS><![CDATA["32"]]></CR_FLAGS>
            <CR_CPNAME><![CDATA[" "]]></CR_CPNAME>
            <CR_TRNAME><![CDATA[" "]]></CR_TRNAME>
            <MTIME><![CDATA["2222222222"]]></MTIME>
      </CR>

What needs to change in the XSLT file to do this????
Cheers
Matt


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
     version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:sql="urn:schemas-microsoft-com:xml-sql"
     exclude-result-prefixes="sql"
     >
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>

<xsl:template match="/ | node()">
     <xsl:copy>
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates select="node()"/>
     </xsl:copy>
</xsl:template>

<xsl:template match="@*">
     <xsl:copy>
     </xsl:copy>
</xsl:template>

<xsl:template match="*">
     <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@*"/>
          <xsl:apply-templates select="node()"/>
     </xsl:element>
</xsl:template>

</xsl:stylesheet>
0
Comment
Question by:pclarkin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
metalmickey earned 375 total points
ID: 13484825
Creating CDATA sections with XSLT

http://www.azureus.com/xml/art_creating_cdata_sections_in_xslt.htm


See examples 5 and 6


Hope this helps

MM
0
 

Author Comment

by:pclarkin
ID: 13489839
OK that makes sense. Now I need to work out how to get the <cdata> tags into my <cr>
so it needs to look like
<CR>
          <CR_NAME>
                            <cdata>
                                        <![CDATA["INT-Afghanistan"]]>
                             </cdata>
          </CR_NAME>
etc.

At the moment it's generated from SQL Server using the for xml explicit command like

SELECT 1                  as Tag,
       NULL                 as Parent,
      '<![CDATA[' + CR_NAME + ']]>' as [CR!1!CR_NAME!XML],
etc
FROM CR
FOR XML EXPLICIT

How do I nest this cdata tag in?
0
 

Author Comment

by:pclarkin
ID: 13491154
Don't worry - I see you can put multiple entrys in the cdata-section-elements declaration.

Cheers.
0

Featured Post

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question