|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error when applying stylesheet to xml with & character
I am a newbie to XML/XSL and I was hoping someone could help.
I am retrieving records from the database that could contain the & character and creating an xml document from the records returned. When trying to apply a styelsheet to this xml I get an error when finding an & in the string. For example here is the xml: <data> <row> <col>3902222</col> <col>FAIRVIEW & COLLINS</col> </row> </data> And here is the select in the xsl: <xsl:for-each select="col"> <TD valign="top"> <xsl:choose> <xsl:when test="position() = 1"> <A href="displayData.jsp"> <b> <xsl:value-of select="."/> </b> <BR/> </A> </xsl:when> <xsl therwise><xsl:value-of select="." /> <BR/> </xsl therwise></xsl:choose> </FONT> </TD> </xsl:for-each> </TR> </xsl:for-each> Here is the error: javax.servlet.jsp.JspException: Error applying stylesheet output.xsl Expected name instead of . I have tried disable-output-escaping = "yes" and that does not work. Can someone help? Thanks. |
|
#2
|
|||
|
|||
|
Hello. You need to use the entity & in place of & and < in place of "<" when transforming XML...how are you retrieving your records?
Is it possible to 'cleanse' the data string before enclosing it in the <col> tag? (i.e. replace & refrences with & and < with <) |
|
#3
|
|||
|
|||
|
Thanks for your reply.
I am retrieving the records via jdbc/sql. I have tried to replace the & dynamically while retrieving the records with something else, and the change is reflected in the xml, but I still get the error when applying the stylesheet. -AW Quote:
|
|
#4
|
|||
|
|||
|
can you include the whole XSL file? and a sample XML file (is data the root node?)
Something you could try would be to escape the <col> text by wrapping a CDATA around it, i.e.: <col><![CDATA[ FAIRVIEW & COLLINS ]]></col> this will also allow you to specify HTML which will be spit out to the browser (rather than being interpretted as XML). |
|
#5
|
||||
|
||||
|
True, but if he can wrap the data in CDATA tags, he could just do & instead of &, correct?
Do you have any control over the base xml document? If you do that is, of course, the best/easiest solution. The xml translator replaces entity values in the xml prior to applying the stylesheet (if any), so I don't believe an xsl solution is possible. (given: I've been wrong before and would welcome a learning experience). |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Error when applying stylesheet to xml with & character |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|