471,320 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,320 software developers and data experts.

Sending XML Content (with < >) as value of an attributes to Object tag in HTML

Hi,

What I am trying to do:
=======================

I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>…………
<thead>……</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
the object using Object tag.

So I have written the xsl as

<object classid="………..">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup"/>
</xsl:attribute>
</object>

Here the HTMLContent is an attribute of the object which will be
interpreted by the C# objeect class aptly. "tgroup" template would
give the entire table content ( "<table>………… <thead>……</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>" ).

This XSL should be transformed as

<object classid="……." HTMLContent="<table>………… <thead>……</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>">

But the table tag value is going as blank to the HTMLContent
attribute.
i.e,

<object classid="……." HTMLContent="">

But if I give some thing like

<object classid="………..">
<xsl:attribute name="HTMLContent">
Sample
</xsl:attribute>
</object>

The XSL transforms as

<object classid="……." HTMLContent="Sample">
</object>

I really don't understand why the table content is not getting in to
the HTMLContent attribute of Object tag. Is there a way where I can do
like this.

I am struck up in this for a long time. Please help me out.

Thanks and Regards,
-Eshrath.
Jul 20 '05 #1
2 3037
Hi,

Not sure trying to put markup inside an attribute is ever the best idea?
I've never used the <object> much - are you sure you can't put the markup as
the content in some way (maybe namespaced?).

But anyway, to put markup into an attribute using XSL you will need to do
your own escaping of the tags, e.g.

== XML ==============================
<?xml version="1.0"?>
<tgroup>
<table border="1">
<!-- comment -->
<?pi something?>
<thead>hd</thead>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</tgroup>
== end of XML =======================

== XSL ==============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup" mode="esc-start"/>
</xsl:attribute>
</object>
</body>
</html>
</xsl:template>

<xsl:template match="*" mode="esc-start">
<xsl:apply-templates mode="esced"/>
</xsl:template>

<xsl:template match="*" mode="esced">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt/;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>

<xsl:template match="@*" mode="esced">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="comment()" mode="esced">
<xsl:text>&lt;!--</xsl:text>
<xsl:value-of select="."/>
<xsl:text>--&gt;</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction()" mode="esced">
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text>?&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
== end of XSL =======================

You could etend this further with a template (in mode "esced") that looked
for HTML tags that didn't require closing properly (i.e. <br>, <hr>, etc.),
e.g. adding the template...

<xsl:template match="*[contains('|br|hr|',concat('|',
translate(name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'),'|'))]" mode="esced">
<xsl:choose>
<xsl:when test="node()">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator
"Eshrath" <es*****@gmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi,

What I am trying to do:
=======================

I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>....
<thead>..</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
the object using Object tag.

So I have written the xsl as

<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup"/>
</xsl:attribute>
</object>

Here the HTMLContent is an attribute of the object which will be
interpreted by the C# objeect class aptly. "tgroup" template would
give the entire table content ( "<table>.... <thead>..</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>" ).

This XSL should be transformed as

<object classid="..." HTMLContent="<table>.... <thead>..</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>">

But the table tag value is going as blank to the HTMLContent
attribute.
i.e,

<object classid="..." HTMLContent="">

But if I give some thing like

<object classid=".....">
<xsl:attribute name="HTMLContent">
Sample
</xsl:attribute>
</object>

The XSL transforms as

<object classid="..." HTMLContent="Sample">
</object>

I really don't understand why the table content is not getting in to
the HTMLContent attribute of Object tag. Is there a way where I can do
like this.

I am struck up in this for a long time. Please help me out.

Thanks and Regards,
-Eshrath.

Jul 20 '05 #2
Hi,

Not sure trying to put markup inside an attribute is ever the best idea?
I've never used the <object> much - are you sure you can't put the markup as
the content in some way (maybe namespaced?).

But anyway, to put markup into an attribute using XSL you will need to do
your own escaping of the tags, e.g.

== XML ==============================
<?xml version="1.0"?>
<tgroup>
<table border="1">
<!-- comment -->
<?pi something?>
<thead>hd</thead>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</tgroup>
== end of XML =======================

== XSL ==============================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup" mode="esc-start"/>
</xsl:attribute>
</object>
</body>
</html>
</xsl:template>

<xsl:template match="*" mode="esc-start">
<xsl:apply-templates mode="esced"/>
</xsl:template>

<xsl:template match="*" mode="esced">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt/;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:template>

<xsl:template match="@*" mode="esced">
<xsl:text> </xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="comment()" mode="esced">
<xsl:text>&lt;!--</xsl:text>
<xsl:value-of select="."/>
<xsl:text>--&gt;</xsl:text>
</xsl:template>

<xsl:template match="processing-instruction()" mode="esced">
<xsl:text>&lt;?</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text> </xsl:text>
<xsl:value-of select="."/>
<xsl:text>?&gt;</xsl:text>
</xsl:template>

</xsl:stylesheet>
== end of XSL =======================

You could etend this further with a template (in mode "esced") that looked
for HTML tags that didn't require closing properly (i.e. <br>, <hr>, etc.),
e.g. adding the template...

<xsl:template match="*[contains('|br|hr|',concat('|',
translate(name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'),'|'))]" mode="esced">
<xsl:choose>
<xsl:when test="node()">
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
<xsl:apply-templates mode="esced"/>
<xsl:text>&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>&gt;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>&lt;</xsl:text>
<xsl:value-of select="name()"/>
<xsl:apply-templates select="@*" mode="esced"/>
<xsl:text>&gt;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
HTH
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator

"Eshrath" <es*****@gmail.com> wrote in message
news:4f*************************@posting.google.co m...
Hi,

What I am trying to do:
=======================

I need to form a table in html using the xsl but the table that is
formed is quite long and cannot be viewed in our application. So we
are writing one object in C# which will take the entire table tag
contents and renders. Ie., we need to pass "<table>....
<thead>..</thead>. <tr>.<td> <td>..<tr>.<td> <td> </table>" content to
the object using Object tag.

So I have written the xsl as

<object classid=".....">
<xsl:attribute name="HTMLContent">
<xsl:apply-templates select="tgroup"/>
</xsl:attribute>
</object>

Here the HTMLContent is an attribute of the object which will be
interpreted by the C# objeect class aptly. "tgroup" template would
give the entire table content ( "<table>.... <thead>..</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>" ).

This XSL should be transformed as

<object classid="..." HTMLContent="<table>.... <thead>..</thead>.
<tr>.<td> <td>..<tr>.<td> <td> </table>">

But the table tag value is going as blank to the HTMLContent
attribute.
i.e,

<object classid="..." HTMLContent="">

But if I give some thing like

<object classid=".....">
<xsl:attribute name="HTMLContent">
Sample
</xsl:attribute>
</object>

The XSL transforms as

<object classid="..." HTMLContent="Sample">
</object>

I really don't understand why the table content is not getting in to
the HTMLContent attribute of Object tag. Is there a way where I can do
like this.

I am struck up in this for a long time. Please help me out.

Thanks and Regards,
-Eshrath.

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fredrik Melin | last post: by
1 post views Thread by Aaron | last post: by
6 posts views Thread by Chris Fink | last post: by
7 posts views Thread by Nathan Sokalski | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.