Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Putting xml in attribute

3 views
Skip to first unread message

sham

unread,
May 4, 2006, 9:21:14 AM5/4/06
to
Hi to all,

I have an xml document which has the contents :

<series>
<dataset id="dataset_1" name="Client - number unplanned">
<data id="dataset_1_1" value="1"/>
<data id="dataset_1_2" value="2"/>
<data id="dataset_1_3" value="3"/>
<data id="dataset_1_4" value="4"/>
<data id="dataset_1_5" value="5"/>
<data id="dataset_1_6" value="6"/>
<data id="dataset_1_7" value="7"/>
<data id="dataset_1_8" value="8"/>
<data id="dataset_1_9" value="9"/>
<data id="dataset_1_10" value="10"/>
<data id="dataset_1_11" value="11"/>
<data id="dataset_1_12" value="12"/>
</dataset>
</series>

I need to create an XSL document that will be applied to the about XML doc
and give on line as

<Row firstattribute=" <dataset id="dataset_1" name="Client - number
unplanned"><data id="dataset_1_1" value="1"/>...</dataset>" />

What XSLT or xpath function do I need to extact the above code and insert it
into an attribute.

Sham.


Martin Honnen

unread,
May 4, 2006, 9:30:12 AM5/4/06
to

sham wrote:


> I need to create an XSL document that will be applied to the about XML doc
> and give on line as
>
> <Row firstattribute=" <dataset id="dataset_1" name="Client - number
> unplanned"><data id="dataset_1_1" value="1"/>...</dataset>" />

That is not well-formed XML at all, '<' would need to be escaped as
'&lt;' for instance, '"' as '&quot;'.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

sham

unread,
May 4, 2006, 9:35:19 AM5/4/06
to
Hi Martin,

What we have is a client dataset (an in memory table) that works by giving
it some data in the format :

<ROW attr= "" etc ?>

This component handles the escaping. But I need to create an XSLT script
that will give us the row with the XML apart of the attribute. Can this be
done?

Sham.
"Martin Honnen" <maho...@yahoo.de> wrote in message
news:%23VbEg73...@TK2MSFTNGP05.phx.gbl...

Martin Honnen

unread,
May 4, 2006, 12:14:28 PM5/4/06
to

sham wrote:


> This component handles the escaping. But I need to create an XSLT script
> that will give us the row with the XML apart of the attribute. Can this be
> done?

I am not sure I understand what you want to achieve. If you want XML to
be a part of an attribute value then you need to escape the XML e.g.
like this stylesheet does

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="dataset">
<Row>
<xsl:attribute name="firstattribute"><xsl:apply-templates
select="." mode="serialize" /></xsl:attribute>
</Row>
</xsl:template>

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

<xsl:template match="@*" mode="serialize">
<xsl:text> </xsl:text>
<xsl:value-of select="concat(name(), '=&quot;', ., '&quot;')" />
</xsl:template>

</xsl:stylesheet>

Applied to your XML sample the result is then

<Row firstattribute="&lt;dataset id=&quot;dataset_1&quot;
name=&quot;Client - number unplanned&quot;&gt;&lt;data
id=&quot;dataset_1_1&quot; value=&quot;1&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_2&quot; value=&quot;2&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_3&quot; value=&quot;3&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_4&quot; value=&quot;4&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_5&quot; value=&quot;5&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_6&quot; value=&quot;6&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_7&quot; value=&quot;7&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_8&quot; value=&quot;8&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_9&quot; value=&quot;9&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_10&quot;
value=&quot;10&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_11&quot;
value=&quot;11&quot;&gt;&lt;/data&gt;&lt;data
id=&quot;dataset_1_12&quot;
value=&quot;12&quot;&gt;&lt;/data&gt;&lt;/dataset&gt;"></Row>

sham

unread,
May 4, 2006, 2:38:40 PM5/4/06
to
Thanks Martin,

Just what I needed. We are using a 3rd party component and we have to
construct the xml in a certain format.

Once again, thanks.

Sham.

"Martin Honnen" <maho...@yahoo.de> wrote in message

news:OGnDTX5b...@TK2MSFTNGP05.phx.gbl...

Martin Honnen

unread,
May 5, 2006, 12:41:27 PM5/5/06
to

sham wrote:

> We are using a 3rd party component and we have to
> construct the xml in a certain format.

Out of curiosity, which component exactly is that that requires to put
the markup of XML nodes escaped into an attribute value?

0 new messages