amcc
amcc

Reputation: 2688

XSLT - Ampersand in & entity breaking transformation

I am doing my transformation in php.

I am receiving a large XML file to transform - which works fine however inside a node there is a url that contains the & character (encoded to &) ie

<web:cacheurl>http://cc.bingj.com/cache.aspx?q=adewy&amp;d=4573100964054074&amp;w=95e613ec,b3e54511</web:cacheurl>

All well and good I thought, however the & in the &amp; appears to be breaking any transformations on that node AND all nodes that appear after it in the xml.

If I strip all & out of the XML to just amp; the problem is fixed, hence debugged - I really don't want to have to strip them out and then put them back in after the transformation, it's a bit hacky. Any ideas?

Upvotes: 0

Views: 1161

Answers (2)

Hans
Hans

Reputation: 181

I had this problem when using Saxon 9.1 xslt processor in Stylus studio 2011. When using Microsoft MSXML 6 processor, problem disappeared.

Update:

problem only occurs when using ampersand in value of attribute...

Upvotes: 0

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243579

I cannot reproduce this alleged problem.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>
</xsl:stylesheet>

when applied on the provided XML document (with added namespace declaration, to make it well-formed):

<web:cacheurl xmlns:web="some:web">http://cc.bingj.com/cache.aspx?q=adewy&amp;d=4573100964054074&amp;w=95e613ec,b3e54511</web:cacheurl>

produces the wanted, correct result:

<web:cacheurl xmlns:web="some:web">http://cc.bingj.com/cache.aspx?q=adewy&amp;d=4573100964054074&amp;w=95e613ec,b3e54511</web:cacheurl>

this same result is produced by all nine XSLT (both 1.0 and 2.0) processors that I use.

Upvotes: 2

Related Questions