Solved

formating xml content

Posted on 2002-06-11
7
205 Views
Last Modified: 2013-11-19

I have a xml tag like this in my xml object,

<description>
<i>Hello</i><b>hai</b>
</description>

note:here <i>Hello</i><b>hai</b> is not the child tag or sibling tag of description.It is the content of the description tag.

Now What I want is when I put <xsl:value-of select="description"/> or <xsl:copy-of select="description"/> in my xsl file and transform it using XSLT, I want it in the formatted way.(i.e hai should be italic and hello should be bold).

But it is coming as such, since it is the content of the description tag.

Can anybody help?

regards
Shanmugaraja

0
Comment
Question by:dsraja
  • 4
  • 3
7 Comments
 

Expert Comment

by:dglachs
Comment Utility
Hello,

There is one big mistake: Your code portion "<i>Hello</i><b>hai</b>" is stored the following way as content of your description node:

&lt;i&gt;Hello&lt;/i&gt;&lt;b&gt;hai&lt;/b&gt;

this means: an xml document may not contain any <> characters in a "PCDATA" node. The characters <,>,&,",' are translated as mentioned.

One possible solution for you is to use a CDATA-Node such as:

<![CDATA[<i>Hello</i><b>hai</b>]]>

Those nodes are not parsed and may contain not well-formed content. The other possible solution is to store the "i"-node with content and the "b"-node with content as part of your xml-object.

Hope this helps

regards
Dietmar
0
 

Author Comment

by:dsraja
Comment Utility
Hello Dietmar,

Thanks for your suggestions.

If I put the node as <![CDATA[<i>Hello</i><b>hai</b>]]>

I am getting it as such, instead I want it in Italic and Bold format when I use <xsl:value-of select="description"/>
0
 

Author Comment

by:dsraja
Comment Utility
Hello Dietmar,

Thanks for your suggestions.

If I put the node as <![CDATA[<i>Hello</i><b>hai</b>]]>

I am getting it as such, instead I want it in Italic and Bold format when I use <xsl:value-of select="description"/>
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Expert Comment

by:dglachs
Comment Utility
Hello again,

you are trying to output the code via XSLT. This is a problem since the XSLT Parser may output only well formed content, and, although we have now a CDATA-Node with <,>,& characters, the XSL Parser converts the characters to &lt; and so on.

I suggest the following: Use your own "bold", "invert" elements in your xml-file such as:

<description>
<bold>Bold</bold><invert>Inverted</invert>
</description>

Then you can use the following style-sheet to get the desired result:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/>
<xsl:template match="description">
<html>
     <head>
          <title></title>
     </head>
     <body><xsl:apply-templates/></body>
</html>
</xsl:template>
<xsl:template match="bold">
<b><xsl:value-of select="."/></b>
</xsl:template>
<xsl:template match="invert">
<i><xsl:value-of select="."/></i>
</xsl:template>
</xsl:stylesheet>


Hope this helps (again)

Best regards
Dietmar
0
 

Author Comment

by:dsraja
Comment Utility
Hello Dietmar,

I'll tell you the exact problem.

I don't have the control over the content of the description.It is coming from the database.

The description is formatted using a tool and entered into the database.it can be of any html format like,
<p align="center"> <font color="red" size="3"> etc..

So those values are stored into the database using htmlspecialchars function of php.so that may be like &lt;$gt;&amp; etc..

What I will do is, I read it from the database as such and build the description tag using $xmlobj->new_child() method. I got to show it in the page as such they have formatted using the tool(i.e the same design,color alignmemnt etc..)

I hope the content will be of well formatted one.I just need to translate all html entities.

So what can be done??

Also can you suggest me a method with which I can replace newline into <br/>

Regards,
Shanmugaraja
0
 

Accepted Solution

by:
dglachs earned 20 total points
Comment Utility
Hello Shanmugaraja,

as with the first idea - use a CDATASection. This gives you the opportunity to store "unknown" HTML-Content.

An example:

$cdata= $doc->create_cdata_section( $content );
$description->append_child( $cdata );

Now you should have an xml structure like this:

<description><![CDATA[<p><font ... >]]></description>

To retrieve the content of the cdata section use the following:

$cdata = $description->first_child();
$content = $cdata->get_content();

Retrieving the CDATASection within a stylesheet will go like this.
<xsl:template match="description">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>

The second attribute of "value-of" should prevent from translating the characters again.

Best regards
Dietmar




0
 

Author Comment

by:dsraja
Comment Utility
Hello Dietmar,

Thanks for your valuable suggestion.Atlast it worked for me.

I put <xsl:value-of select="description" disable-output-escaping="yes">, which has given me the formatted output.

With thanks and Regards,
Shanmugaraja
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now