473,382 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How can I get attribute values to not get converted from ' to ' or & to & or < to > ?

Hi, my mind is going crazy. I have tried everything I can think of to
no
avail.
I have tried Disable Output Escaping.
I tried to think of a way of enclosing the attribute data in a CDATA
element. That did not parse.

Here is my question:

How can I get attribute values to not get converted from ' to '
or & to & or < to > ?
It seems like if I take the xsl:value-of an attribute and then output
that
value into another xml it get's converted.

The problem is I am importing this stuff into a DB and I need to keep
all
those ' and other escapings..

Also, is there a way to do something like this
<![CDATA[
<xsl:value-of select="@CATEGORY" />
]]>

The problem with this is it gives me
<xsl:value-of select="@CATEGORY" />

where I want
Men&apos;s Clothing

Thanks any help would be appreciated...
Here is my source xml, XSL, and outfile:

Source XML:

<import>
<CAT>
<row CATEGORY="Men&apos;s Clothing" />
</CAT>
</import>

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

<xsl:output indent="yes" method="xml" />
<xsl:strip-space elements="*"/>

<xsl:template name="frank_data">

<xsl:param name="id" />
<xsl:element name="frankgroup">
<xsl:attribute name="identifier"><xsl:value-of select="$id"
/></xsl:attribute>
</xsl:element>

</xsl:template>

<xsl:template match="/">

<xsl:element name="import">
<xsl:apply-templates />
</xsl:element>

</xsl:template>

<xsl:template match="CAT">
<xsl:for-each select="*">
<xsl:call-template name="frank_data">
<xsl:with-param name="id" select="@CATEGORY" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output:

<import>
<frankgroup
id="Men's Clothing" />
</import>

Jul 20 '05 #1
12 9400

How can I get attribute values to not get converted from &apos; to '
or &amp; to & or &lt; to > ?
The whole point about &lt; is that it means the same thing as > (not
always in element content if the preceding two characters were ]] but in
attribute values they always mean the same thing.
If you go
<foo bar="&gt;"/><foo bar=">"/> Then XSLT will see identical input from
the two forms, and it may use either form on output. It has no way of
knowing which form was used, any more than it has of knowing whther yiou
used " or ' to surround the attribute value.
The problem is I am importing this stuff into a DB and I need to keep
all those &apos; and other escapings..


If that import mechanism is not aware of XML conventions so is broken by
XML quoting syntax they you will have to use the text output method of
xslt and write out the literal tags that you want rather than allowing
XSLT to linearise an element tree for you. But you lose most of the
benefits of xslt doing that.

so
<xsl:output method="text"/>
....

<xsl:template match="xyz">
&lt;foo bar="<xsl:value-of select="@CATEGORY"/>" ..../&gt;
....

Also, is there a way to do something like this
<![CDATA[
<xsl:value-of select="@CATEGORY" />
]]>
Well you can do exactly that, as you observe, but then the
<xsl:value-o
is taken as character data not element markup.
The problem with this is it gives me
<xsl:value-of select="@CATEGORY" />
where I want
Men&apos;s Clothing

As I say above If you mean that you had an input string of
Men&apos;s Clothing
and you need it to come out as
Men&apos;s Clothing
and not as
Men's Clothing
then basically you can't use XSLT as the XML parser will report these
two things as the same. So there is no way XSLT can preserve the difference.
David

Jul 20 '05 #2
Hmm, whell what if you want everythign to come out as
&apos; then?
I mean actually I don't care if it comes in as ' or &apos;

I just want it to come out as &apos;

Jul 20 '05 #3
Are there any templates out there for converting all your data from

', <, >, &

to

&apos; &lt; &gt; &amp;

?

Jul 20 '05 #4
In article <11*********************@z14g2000cwz.googlegroups. com>,
Sammy <fr********@gmail.com> wrote:
Hmm, whell what if you want everythign to come out as
&apos; then?


The answer from an XML point of view is that you shouldn't want that!

If you need to enforce it for compatibility with some non-XML system
(such as your database), then you need a special purpose tool to
convert it from "generic XML" to "the subset of XML my application
needs".

-- Richard
Jul 20 '05 #5


Sammy wrote:
Hmm, whell what if you want everythign to come out as
&apos; then?


XSLT gives you a result tree, you would then need to write your own
serializer that follows the conventions you define.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #6
Oh, and I really like your FAQ by the way David...
I've been reading it a lot over the last 2 weeks....

Jul 20 '05 #7
Yeah, but how do HTML peeps do this then?

I mean they use XSL to create HTML all the time and it comes out as
&apos; ??

Am I missing something here?

Those peeps who create HTML have to have it come out in &apos, and
&nsps; and &amp;

Or there HTML won't work...

What do those peeps do?

Jul 20 '05 #8
It would seem like one stategy is to just have it output
HTML?

Does this work?

If I change the <xsl:output element to say HTML

will it output &apos;???

Jul 20 '05 #9
Thanks for all the quick responces by the way.

I appreciate your help....

Jul 20 '05 #10
"Sammy" <fr********@gmail.com> writes:
Yeah, but how do HTML peeps do this then?

I mean they use XSL to create HTML all the time and it comes out as
&apos; ??

Am I missing something here?
yes.
Those peeps who create HTML have to have it come out in &apos, and
&nsps; and &amp;

Or there HTML won't work...
It will work. look at
<p>your&apos;s and your's</p>
in an html browser of your choice. &apos; means the same thing as '
The _only_ time you need to use &apos; is to get a ' in an ' delimited
attribute value
foo='your&apos;s'
XSLT will do that automatically when it's needed.

What do those peeps do?


They let XSLT take care of the details.

David
Jul 20 '05 #11
"Sammy" <fr********@gmail.com> writes:
Oh, and I really like your FAQ by the way David...
I've been reading it a lot over the last 2 weeks....


different david
Jul 20 '05 #12
In article <11*********************@g14g2000cwa.googlegroups. com>,
Sammy <fr********@gmail.com> wrote:
It would seem like one stategy is to just have it output
HTML?

Does this work?

If I change the <xsl:output element to say HTML

will it output &apos;???


No, because ' is perfectly good in HTML as well as in XML.

-- Richard

Jul 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
2
by: Francesco Moi | last post by:
Hello. I designed a form to edit some DataBase's fields. But some of these fields contain '&lt;' and '&gt;' characters. And these characters are '<' and '>' in HTML. So if want to edit these...
2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
6
by: tentstitcher | last post by:
Hi all: I have a source xml document with an element of type string. This element contains something like the following: <stringData> &lt;Header&gt; &lt;Body&gt; </stringData> I would like to apply an...
3
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.