Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL general entity treatment

Status
Not open for further replies.

harebrain

MIS
Feb 27, 2003
1,146
US
Hi all,

I have an XML document that I need to reformat using XSL, basically changing all the attribute="value" stuff to their own child elements. This works great EXCEPT & quot ; and & #34 ; get changed to " (34 is ASCII for ") while & amp ; remains as-is.

Why? Aren't < > & &quot; and ' forbidden in XML aside from their special meanings? So why would an XSL transform screw with the entities? Better yet, why does it only screw with HALF of them?

I've tried
Code:
<xsl:value-of select=&quot;.&quot; disable-output-escaping=&quot;no&quot;/>
and
Code:
<xsl:value-of select=&quot;.&quot; disable-output-escaping=&quot;yes&quot;/>
to try to work around this, but it doesn't make any difference.

I've done this with different parsers, too, and the behavior is the same. What's up with this?

(I've seen this included in other questions here, but this peculiarity itself hasn't been addressed.)

--harebrain
 
Well, because nobody else has an answer for this one, I'll share what I've found. According to :

Only the characters &quot;<&quot; and &quot;&&quot; are strictly illegal in XML. Apostrophes, quotation marks and greater than signs are legal, but it is a good habit to replace them.

So if XML doesn't require use of an entity reference where a quote character is needed, there's no reason why XSLT should preserve those entity references in a result tree.

This also explains the contrary behavior regarding ampersands: the ampersand character is illegal in XML character data, so when data is returned from the result tree it would have to be converted back to an entity reference.

(To w3schools: Why is it a &quot;good habit&quot; to do something that is superfluous?)

(To the W3C: Thanks for the confusion! :))

--harebrain
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top