RE: Using xsl Stylesheet - html view

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Marc

RE: Using xsl Stylesheet - html view

Post by Marc »

Dear George,
Thank you very much for your help and your patience.
It is still not working and I am a short time away to give it up forever...
I will send you now all my written code, this is the last possibility.
My Test1.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Test1.xsl"?>
<root:Bilddatenbank xmlns:root="http://www.w3.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org Test1.xsd">
<!--I have to write root:Bilddatenbank without the root: it does not work and this is something I didn't understand either! -->
<Patient>
<Name>Blatt</Name>
<Vorname>Marc</Vorname>
</Patient>
</root:Bilddatenbank>

My Test1.xsd
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace="http://www.w3.org">
<xs:element name="Bilddatenbank">
<xs:complexType>
<xs:sequence>
<xs:element name="Patient" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Vorname">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

My Test1.xsl:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body bgcolor="#CCFFFF">
<h1 align="center">
Bilderdatenbank
</h1>
<p>
<h2>
<xsl:value-of select="Bilddatenbank/Patient/Name"/>
<!--Only the last name Blatt should appear in the html file but nothing appears
I have no idea why!-->
</h2>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

And what about the <xsl:apply-templates>? Do I need that? If I put this in the body I can see all the data in html but I can't select.
Thank you for your help.

Marc
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Marc,

Your problem is related with namespaces. The root element from your document, Bilddatenbank, belongs to the schema target namespace, that is http://www.w3.org. Now in your XPath expression:
<xsl:value-of select="Bilddatenbank/Patient/Name"/>
you refer to a Bilddatenbank element from no namespace. As this element does not exist you get no results from this expression. If you declare a prefix pointing to that namespace and correctly refer to the Bilddatenbank element you will get the expected result, see sample below:

Code: Select all


<?xml version="1.0" encoding="ISO-8859-1" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:root="http://www.w3.org">
<!-- Note the namespace binding mapping the root prefix to your schema target namespace -->
<xsl:template match="/">
<html>
<body bgcolor="#CCFFFF">
<h1 align="center">
Bilderdatenbank
</h1>
<p>
<h2>
<xsl:value-of select="root:Bilddatenbank/Patient/Name"/>
<!-- See the prefix for Bilddatenbank indicating that this element is from the schema target namespace -->
</h2>
</p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Best Regards,
George
Post Reply