|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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.5Any 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>
<?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=" " string="&nbsp;"/> <xsl:output-character character="" string="<"/> <xsl:output-character character="" string=">"/> <xsl:output-character character="" string="&"/> <xsl:output-character character="" string="""/> </xsl:character-map> <xsl:template match="attribute"><!-- --><xsl:attribute name="{@name}"><xsl:value-of select="translate(.,'<>&"','')"/></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>
<?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>
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








