Jump to content
zecapistolas

XML + XSL + CSS não abre no Google Chrome

Recommended Posts

zecapistolas

Viva,

Cá vai mais uma dúvida de XML.

Tenho algo definido em XML (não interessa bem o que porque é apenas um exemplo) e agora através de transformações XSLT e CSS quero que o XML seja mostrado no browser de uma forma mais agradável ao utilizador.

Abaixo segue todo o código que tenho como exemplo: definição XML ; XSD Schema ; folha de estilos CSS ; transformador XSL .

XML

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="joke.xsl" ?>
<jokes
xsi:noNamespaceSchemaLocation="joke.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<joke id="1" category="animals">
	   <title>Two Cows in a Field</title>
	   <author>John Smith</author>
	   <setup>Two cows are standing in a field eating grass.</setup>
	   <setup>The first cow says: "Moooo!"</setup>
	   <punchline>The second cow says: "Hey, I was just gonna say that!"</punchline>
</joke>
<joke id="2" category="animals">
	   <title>Mad Cows</title>
	   <author>Jane Doe</author>
	   <setup>Two cows are talking.</setup>
	   <setup>The first cow: "Hey, did you hear about that mad cow disease?"</setup>
	   <setup>The second cow: "Yeah, but I'm not worried about it."</setup>
	   <setup>The first cow: "Why not?"</setup>
	   <punchline>The second cow: "I'm a duck."</punchline>
</joke>
</jokes>

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="joke">
	<xs:complexType>
		<xs:sequence>
			<xs:element name="title" type="xs:string"/>
			<xs:element name="author" type="xs:string" minOccurs="0"/>
			<xs:element name="setup" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="punchline" type="xs:string"/>
		</xs:sequence>
		<xs:attribute name="id" use="required" type="xs:unsignedLong"/>
		<xs:attribute name="category" type="xs:string" use="required"/>
	</xs:complexType>
</xs:element>
<xs:element name="jokes">
	<xs:complexType>
		<xs:sequence><xs:element ref="joke" minOccurs="0" maxOccurs="unbounded"/></xs:sequence>
	</xs:complexType>
	<xs:unique name="joke-id">
		<xs:selector xpath=".//joke"/>
		<xs:field xpath="@id"/>
	</xs:unique>
</xs:element>
</xs:schema>

CSS

html { margin: 0; padding: 0; }

i { color: maroon; }

body {
font: 75% georgia, sans-serif;
line-height: 2;
color: white;
background: #fff url(cows.gif) repeat top left;
margin: 20px;
padding: 0;
}

a:link, a:visited {
font-weight: bold;
text-decoration: none;
color: yellow;
}

a:hover, a:active {
text-decoration: underline;
color: white;
}

p { margin-top: 5px; text-align: justify; }                                       
                                                     
              
h1 { color: maroon; }

h3 {                                                  
   font: italic normal 1.5em georgia, sans-serif;     
   letter-spacing: 1px;                                  
   margin-bottom: 0;                                     
   color: maroon;                                        
}

ul { margin: 20px; }

li {
line-height: 2ex;
margin-bottom: 5px;
}

XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="jokes">
	<html>
		<head>
			<title>Jokes</title>
			<link type="text/css" rel="stylesheet" href="joke.css" />
		</head>
		<body>
			<h1>Jokes</h1>
			<ul><xsl:apply-templates select="joke" mode="summary"/></ul>
			<xsl:apply-templates select="joke" mode="full"/>
			<hr/>
		</body>
	</html>
</xsl:template>

<xsl:template match="joke" mode="summary">
	<li><a href="#{@id}" ><xsl:value-of select="title"/></a></li>
</xsl:template>

<xsl:template match="joke" mode="full">
	<hr/>
	<h3><a name="#{@id}"><xsl:value-of select="title"/></a></h3>
	<i><xsl:value-of select="author"/></i>
	<ul>
		<xsl:apply-templates select="setup"/>
		<xsl:apply-templates select="punchline"/>
	</ul>
</xsl:template>

<xsl:template match="setup | punchline">
	<li>
		<xsl:value-of select="."/>
	</li>
</xsl:template>

</xsl:stylesheet>

Dúvida: O XML é perfeitamente mostrado no Firefox 4.0 e Opera 11.10, mas o mesmo não acontece com Google Chrome 12.0.742.12!  (Sistema Linux 64 bits) 😡   😡

Alguém tem ideia do que poderá ser?  🤔

cumps  :(

Share this post


Link to post
Share on other sites
Rui Carlos

Nunca usei XML+XSLT desta forma, por isso nem sei muito bem como anda o suporte dos browsers.

Mas numa pesquisa no Google mencionam problemas com leitura de ficheiros locais e com o MIME type dos ficheiros como possíveis causas de problemas semelhantes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.