xsl-list
[Top] [All Lists]

Re: [xsl] XSL embedded in XML

2011-04-18 08:21:47
I think it's because your top-level element:

    <target xmlns="urn:asdf">

declares the default (no-prefix) namespace for the entire xml+xslt
document.  That has the effect of putting the <html> and all the other
HTML tags into this "urn:asdf" namespace.  Whereas, if you look at the
stand-alone xsl, you have no default namespace defined, so <html> is
in "no namespace".

Try adding xmlns:html='http://www.w3.org/1999/xhtml', and then using
<html:html>, <html:body>, etc.


On Mon, Apr 18, 2011 at 8:16 AM, Gabriel Kleinoscheg
<gabriel(_dot_)kleinoscheg(_at_)gmx(_dot_)at> wrote:
Hello Everybody!

I'm still struggling with the following XML and XSL files. In the first
example I've separated the XML and the XSL:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='test02.xsl'?>
<target xmlns="urn:asdf">
 <title>This is the title</title>
</target>

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:n="urn:asdf" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
 <xsl:output method="html"/>
 <xsl:template match="/">
   <html>
     <head>
       <title>
         <xsl:value-of select="n:target/n:title"/>
       </title>
     </head>
     <body>
       <h1>
         <center>
           <xsl:value-of select="n:target/n:title"/>
         </center>
       </h1>
     </body>
   </html>
 </xsl:template>
 <!--xsl:template match="xsl:stylesheet"/-->
</xsl:stylesheet>

The example above works quite well in every browser. Now comes the
challenge - embedding the XSL into the XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='#test'?>
<!DOCTYPE target [<!ATTLIST xsl:stylesheet id ID #REQUIRED>]>
<target xmlns="urn:asdf">
 <xsl:stylesheet id="test" xmlns:n1="urn:asdf" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output method="html"/>
   <!-- CDA document -->
   <xsl:template match="/">
     <html>
       <head>
         <meta content="text/html; charset=UTF-8"
http-equiv="Content-Type" />
         <title>
           <xsl:value-of select="n1:target/n1:title"/>
         </title>
       </head>
       <body>
         <h1>
           <center>
             <xsl:value-of select="n1:target/n1:title"/>
           </center>
         </h1>
       </body>
     </html>
   </xsl:template>
   <xsl:template match="xsl:stylesheet"/>
 </xsl:stylesheet>
 <title>This is the title</title>
</target>

I've tested this example - it doesn't show correctly in Firefox and IE
but in Safari. Although when I check the generated source with
WebDeveloper in Firefox I see the correct html-code.

If I write

<n1:target xmlns:n1="urn:asdf">
 <n1:title> ... </n1:title>
</n1:title>

everything works perfectly. But why isn't it possible without the
prefixes in the XML? Why does it work, if XML and XSL are separated but
not when they are within one document?

Hope you can help me. Thank you anyway.

regards, Gabriel

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>