XML isnt showing basic text from XSL document

Here should go questions about transforming XML with XSLT and FOP.
WJC1981
Posts: 1
Joined: Fri Sep 01, 2023 1:25 pm

XML isnt showing basic text from XSL document

Post by WJC1981 »

Hi all,

Newbie here so sorry if this is a basic question, basically I have an XML that wont link to my XSL stylesheet, this is what is at the top of my XML document

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="TransformDocument.xsl"?>
<root>
  <listing>
    <seller_info>
The XSL stylesheet is contained within the same folder and is called TransformDocument.xsl, which looks like this

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3org1999/XSL/Transform">
	<xsl:template match="/">
		<html>
			<head></head>
			<body>
				<xsl:apply-templates select="/root/listing"/>
			</body>
		</html>
	</xsl:template>	
	
	<xsl:template match="listing">
		Testing123
	</xsl:template>
	
</xsl:stylesheet>
I am not getting testing123 displaying anywhere when I open the XML file, I dont think its linking because I also just put testing123 in the <body> tags and still nothing was displayed - I have tried this in Chrome and Edge.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML isnt showing basic text from XSL document

Post by Radu »

Hi,
The namespace declaration of your XSLT should be:
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
Other than that maybe web browsers no longer interpret "xml-stylesheet" instructions when loading XML documents. Maybe you need to use Javascript to apply the XSLT.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
InspectorSpacetime
Posts: 38
Joined: Thu Jul 29, 2021 12:02 pm

Re: XML isnt showing basic text from XSL document

Post by InspectorSpacetime »

Hi,

In addition to the namespace issue Radu mentioned:

Modern browsers don't allow XML files to access local XSLT files due to security concerns. More info can be found here:

https://stackoverflow.com/questions/455 ... gle-chrome

So, if your trying to check the transformation with local files in a web browser, it probably will not work anyway. The solution is to use a local host or an XML editor.
Post Reply