• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

XSL string replace function not working

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


I am trying to use a simple xsl string replace function. I am trying to test my code by opening the xml in Mozilla/IE browser.

XML code:

<?xml version="2.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="replace.xsl"?>
<response>
<claim claimNumber="063544577" claimDescription="Costco Claims">
</claim>
</response>



XSL code:

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

<xsl:template match="response">
<xsl:apply-templates select="claim"/>
</xsl:template>

<xsl:template match="claim">
<xsl:value-of select="replace(@claimDescription,"Costco","Walmart")"/>
</xsl:template>

</xsl:stylesheet>




Both browsers are showing same following error

XML Parsing Error: not well-formed
Location: file:///C:/replace.xsl
Line Number 9, Column 51:


Let me know if there is anything that Im missing.


Thanks,
 
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there's a couple of problems there:

(1) There is no version 2.0 of XML, so declaring your XML as version="2.0" isn't going to do anything positive. Perhaps the browsers will ignore that error.

(2) There is a version 2.0 of XSLT, but the browsers don't support it. Perhaps they will ignore that and treat it as version 1.0, although technically they shouldn't.

But the main problem is exactly what the error message says it is. Here's line 9 of your XSLT document:

The problem is that after your select attribute, which looks like this:

there is a bunch more text which looks like this:

That text isn't in an attribute and you can't have loose text like that inside the start tag of an element. Of course that wasn't what you meant, was it? That could be avoided by better use of quoting.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic