XSLT and XPath something wrong

Go To StackoverFlow.com

1

I've been losing lots of time trying to figure out how xslt's work

I have this xml

<?xml version="1.0" encoding="UTF-8"?>

<lvl:map xsi:schemaLocation="http://www.ohmeudeus.com lvlMl-v2.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lvl="http://www.ohmeudeus.com">
   <name>String</name>
   <myColor>fffffffff</myColor>
</lvl:map>

and now i want to make an html, by using xslt, with the word String

so my xslt is something like

   <?xml version="1.0" encoding="UTF-8"?>
   <xsl:stylesheet version="2.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns="http://www.w3.org/1999/xhtml" 
   xmlns:lvl="http://www.ohmeudeus.com lvlMl-v2.xsd">
<xsl:template match="lvl:map">
    <html>
        <head>
            <title>
                normal title
            </title>
            <link href="style.css" rel="stylesheet" type="text/css"/>
        </head>
        <body>
            The name is <xsl:value-of select="name"/>
        </body>
    </html>
</xsl:template>

</xsl:stylesheet>

the result gives me back both name and color like this:

String fffffffff

I don't understand what I'm doing wrong here... please help me...

Also i accept any tips you have to help me to find bugs

2012-04-04 17:52
by Navy Seal


4

It's because the xmlns in your XML:

xmlns:lvl="http://www.ohmeudeus.com"

Does not match the xmlns in your XSLT:

xmlns:lvl="http://www.ohmeudeus.com lvlMl-v2.xsd"
2012-04-04 18:06
by Daniel Haley


1

I've spotted 2 problems.

  • The closing </xsl:stylesheet> is missing.
  • The <xmlns:lvl> should not have a schema location, only the namespace.

After fixing this you should get The name is String.

2012-04-04 18:05
by phlogratos
about the stylesheet closure it was a stack overflow paste error. i removed the lvlMl-v2.xsd from the xmlns:lvl and didnt changed anything but its true that was an erro - Navy Seal 2012-04-04 18:11


0

When I run the posted XSLT with the namespace fixed against the posted XML I get the following. Is this not the required output?

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lvl="http://www.ohmeudeus.com">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>normal title</title>
      <link href="style.css" rel="stylesheet" type="text/css" />
   </head>
   <body>The name is String</body>
</html>
2012-04-04 19:19
by Kevan
"When I run the posted XLST with the namespace fixed against the posted XML I get the following." - The namespace was the only issue - Daniel Haley 2012-04-05 01:27
Ads