[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Attribute value quoting with Saxon8

Subject: Re: Attribute value quoting with Saxon8
From: Victor Toni <xsl-list@xxxxxxxxx>
Date: Sat, 20 Aug 2005 11:45:29 +0200
christmas qoutes
I hoped this would be an error on user side so that I could fix this fast.
I thought that only double qoutes could embed singels qoutes and not otherwise around.


The problem I encounter here is that I could have something like <input onclick="<% get_action("submit"); %>" /> .
If "<% get_action("submit"); %>" returns something like "alert('Please check value!');" this works with double qoutes but would be problematic with single qoutes.


Is there is an option to change this behaviour?

Kindest regards,
Victor

Michael Kay wrote:

Saxon is trying to be helpful here; if you generate an attribute value
containing double quotes, it uses single quotes as the delimiter to try and
make it valid XML/HTML if it can. Is this output really being passed to
software that requires double quotes around the attribute value? If so, I'm
afraid the only solution is to generate the whole start tag "by hand".

Michael Kay
http://www.saxonica.com/




-----Original Message-----
From: Victor Toni [mailto:xsl-list@xxxxxxxxx] Sent: 19 August 2005 21:52
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Attribute value quoting with Saxon8


I am trying to change some web pages for an embbeded device from ancient
HTML to XML which should ease changes of the resulting pages.
The resulting pages will be _not_ valid HTML because they are parsed by
the HTTP server of the device and then the hopefully valid result will
be returned to the browser.


However I have some trouble to create attributes which values are in
double qoutes if the value itself contains double qoutes.

My environment:
     JDK 1.5.0_04 (on WinXP)
     Saxon-B 8.5

Any help is greatly appreciated.

Kindest regards,
Victor

test.xml
------------------

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

<test>
<a>
<attribute name="href"><![CDATA[<% get_href(); %>]]></attribute>
<text>Works</text>
</a>


<a>
<attribute name="href"><![CDATA[<% get_value("href"); %>]]></attribute>
<text>Doesn't work as expected</text>
</a>
</test>



test.xsl ------------------

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

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

<xsl:param name="file"/>

<xsl:output
	encoding="UTF-8"
	method="xhtml"
	indent="yes"
	use-character-maps="cm1"
/>

<xsl:character-map name="cm1">
	<xsl:output-character character="&#160;" string="&amp;nbsp;"/>
	<xsl:output-character character="&#xE001;" string="&lt;"/>
	<xsl:output-character character="&#xE002;" string="&gt;"/>
	<xsl:output-character character="&#xE003;" string="&amp;"/>
	<xsl:output-character character="&#xE004;" string="&quot;"/>
</xsl:character-map>

<xsl:template match="attribute"><!--
--><xsl:attribute name="{@name}"><xsl:value-of select="translate(.,'&lt;&gt;&amp;&quot;','&#xE001;&#xE002;&#x
E003;&#xE004;')"/></xsl:attribute><!--


--></xsl:template>

<!--
just copy all nodes without a specialized template
-->
<xsl:template match="*|@*"><xsl:copy><xsl:apply-templates select="@*"/><xsl:apply-templates/></xsl:copy></xsl:template>


<!--
normalize excessive use of whitespaces
-->
<xsl:template match="text()">
<xsl:if test="string-length(normalize-space(.)) != 0">
<xsl:if test="starts-with(.,' ')"><xsl:text> </xsl:text></xsl:if><xsl:value-of select="normalize-space(.)"/><xsl:if test="ends-with(.,' ')"><xsl:text> </xsl:text></xsl:if>
</xsl:if>
</xsl:template>


</xsl:stylesheet>


test-result.html ------------------

<?xml version="1.0" encoding="UTF-8"?><test>
   <a href="<% get_href(); %>">
      <text>Works</text>
   </a>
   <a href='<% get_value("href"); %>'>
      <text>Doesn't work as expected</text>
   </a>
</test>

test-expected.html
------------------

<?xml version="1.0" encoding="UTF-8"?><test>
   <a href="<% get_href(); %>">
      <text>Works</text>
   </a>
   <a href="<% get_value("href"); %>">
      <text>Doesn't work as expected</text>
   </a>
</test>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.