XSL Displaying Problem

Here should go questions about transforming XML with XSLT and FOP.
ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

XSL Displaying Problem

Post by ivan603 » Wed Nov 09, 2005 12:47 pm

Hi all, i have a problem in XSL.

Actually i have a xml string that contain some XML nodes. I define one of the node as Base64Binary data type. I use <xsl:value-ofselect='nodeName'> in xsl to get the value, but the problem i found is it returned the encoded string to me, not the original string. Can someone please help me to solve this problem?

Value in XML node string:
<MessageContent xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64">SABlAGwAbABvAA==</MessageContent>

The original message of the node:
Hello

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache » Wed Nov 09, 2005 3:15 pm

Hello,

In XML documents the base64 type is used for encoding illegal XML characters. You can't decode base64 encoded strings in standard XSLT, 1.0 or 2.0. You should use an extension function of the XSLT processor and if the output method of the stylesheet is XML you should enclose the base64 decoded string in a CDATA section. For that specify to the processor that the element that will contain the base64 decoded string has CDATA content:

Code: Select all

<xsl:output cdata-section-elements="a" method="xml"/>
where <a> contains the base64 decoded string</a>.

An alternative is to leave the string base64 encoded in the XSLT stylesheet output and postprocess the output with other tool.

I hope it helps,
Sorin

ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

Post by ivan603 » Thu Nov 10, 2005 5:52 am

Hi sorin, thank u for your help.

But my knowledge in XSL is quite limited. Can you explain how to get the string in XSL?
Actually my XSl already contains <xsl:output method="html" version="4.0"/>, when i add
<xsl:output cdata-section-elements="a" method="xml"/>, a problem occured.
Is it using <![CData[ <xsl:value-of select=''>]]> in XSl to get the value? I tried and it exactly returned the same string to me.

I think i need to explain why i'm using base64 data type in my xml node. Actually, i send a request xml string from asp to vb(server side). Then after processing the data, vb will send back a response in xml string which contains some nodes to asp. Then this string will be used in XSL code. The content of the node may contains a carriage return, for example:

Hello, every body

This is testing message

If i define the node type as string in XSD schema, i found that the carriage return was lost. I don't know why. So i change the node data type in XSD schema from string to base64Binary. If i do that, before going to XSL, i write the value of the node in asp, it shown me the original message including the carriage return. But if it is lost when i define it as string data type.

Do u or some body have idea to solve the problem?

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Thu Nov 10, 2005 6:06 pm

Hi Ivan,

XSLT will not remove the new line characters if you to not normalize the text when you emit it to the output, for instance, on teh following XML:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<MessageContent>

Hello, every body

This is testing message

</MessageContent>
if you apply a stylesheet like:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="MessageContent">
<MessageContent>
<xsl:value-of select="."/>
</MessageContent>
</xsl:template>
</xsl:stylesheet>
the result will be

Code: Select all


<?xml version="1.0" encoding="UTF-8"?><MessageContent>

Hello, every body

This is testing message

</MessageContent>
As you can see the new lines are present.

--- start guessing ---
What I guess is that in your case you are looking at the HTML document as it is rendered by a browser, in that case you will not see the new lines even though they are present in the HTML source. You should check the source to see if the new lines are there or not. If you want new lines in the HTML rendered result you can either place the content inside a <pre> element or you should insert one <br> element in the place of each new line.
--- end guessing ---

Best Regards,
George

ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

Post by ivan603 » Fri Nov 11, 2005 10:01 am

Hi george, thanks for your suggestion. I use

<xsl:apply-templates select=".//MessageContent"/>

<xsl:template match="MessageContent">
<pre>
<xsl:value-of select="."/>
</pre>
</xsl:template>

the result contains the carriage return character. But how do i apply the disable-output-escaping in this case? For instance, on the following XML node value:

<MessageContent>
<B>Hello, every body</B>

<Font color="#FF0000">This is testing message</Font>
</MessageContent>

My expected output should not contains the <B>...</B> and <Font color="#FF0000">...</Font> tags.

How can i do that?

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Fri Nov 11, 2005 11:44 am

Hi Ivan,

You should not get B and Font elements if you use value-of. If you want B and Font elements to appear in the output use copy of, like below:

Code: Select all


    <xsl:template match="MessageContent">
<pre>
<xsl:copy-of select="./node()"/>
</pre>
</xsl:template>
Best Regards,
George

ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

Post by ivan603 » Sat Nov 12, 2005 3:45 am

Hi georg, i use <xsl:copy-of select="./node()"/> but the output still same.

Below is my html code in XSL:

<Table>
<TR>
<TD>
<Span>
<xsl:attribute name="class">msgContent</xsl:attribute>
<xsl:apply-templates select=".//MessageContent"/>
</Span>
</TD>
</TR>
</Table>

<xsl:template match="MessageContent">
<pre>
<xsl:copy-of select="./node()"/>
</pre>
</xsl:template>

Even the msgContent class has not been applied. How can i do that?

Thank you. :wink:

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Post by george » Mon Nov 14, 2005 11:57 am

Hi,

It works for me, here it is a complete example.

test.xml

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<MessageContent>
<B>Hello, every body</B>

<Font color="#FF0000">This is testing message</Font>
</MessageContent>
test.xsl

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<Table>
<TR>
<TD>
<Span>
<xsl:attribute name="class">msgContent</xsl:attribute>
<xsl:apply-templates select=".//MessageContent"/>
</Span>
</TD>
</TR>
</Table>
</xsl:template>
<xsl:template match="MessageContent">
<pre>
<xsl:copy-of select="./node()"/>
</pre>
</xsl:template>
</xsl:stylesheet>
result

Code: Select all


<?xml version="1.0" encoding="utf-8"?><Table><TR><TD><Span class="msgContent"><pre>
<B>Hello, every body</B>

<Font color="#FF0000">This is testing message</Font>
</pre></Span></TD></TR></Table>
Best Regards,
George

ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

Post by ivan603 » Tue Nov 15, 2005 7:00 am

Hi george,



Is your output is in Bold and Red color?

Hello, every body -> should be displayed in Bold text

This is testing message -> should be displayed in Red color

The expected output should not contains the start tag and end tag of <Bold> and <Font>

Thank you. :wink:

ivan603
Posts: 8
Joined: Wed Nov 09, 2005 12:31 pm

Post by ivan603 » Tue Nov 15, 2005 7:01 am

Hi george,

Is your output is in Bold and Red color?

Hello, every body -> should be displayed in Bold text

This is testing message -> should be displayed in Red color

The expected output should not contains the start tag and end tag of <Bold> and <Font>

Thank you. :wink:

Post Reply