Re: [xsl] XSL embedded in XML

Subject: Re: [xsl] XSL embedded in XML
From: Chris Maloney <voldrani@xxxxxxxxx>
Date: Mon, 18 Apr 2011 09:21:34 -0400
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.kleinoscheg@xxxxxx> 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">
> B <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";>
> B <xsl:output method="html"/>
> B <xsl:template match="/">
> B  B <html>
> B  B  B <head>
> B  B  B  B <title>
> B  B  B  B  B <xsl:value-of select="n:target/n:title"/>
> B  B  B  B </title>
> B  B  B </head>
> B  B  B <body>
> B  B  B  B <h1>
> B  B  B  B  B <center>
> B  B  B  B  B  B <xsl:value-of select="n:target/n:title"/>
> B  B  B  B  B </center>
> B  B  B  B </h1>
> B  B  B </body>
> B  B </html>
> B </xsl:template>
> B <!--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">
> B <xsl:stylesheet id="test" xmlns:n1="urn:asdf" version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> B  B <xsl:output method="html"/>
> B  B <!-- CDA document -->
> B  B <xsl:template match="/">
> B  B  B <html>
> B  B  B  B <head>
> B  B  B  B  B <meta content="text/html; charset=UTF-8"
> http-equiv="Content-Type" />
> B  B  B  B  B <title>
> B  B  B  B  B  B <xsl:value-of select="n1:target/n1:title"/>
> B  B  B  B  B </title>
> B  B  B  B </head>
> B  B  B  B <body>
> B  B  B  B  B <h1>
> B  B  B  B  B  B <center>
> B  B  B  B  B  B  B <xsl:value-of select="n1:target/n1:title"/>
> B  B  B  B  B  B </center>
> B  B  B  B  B </h1>
> B  B  B  B </body>
> B  B  B </html>
> B  B </xsl:template>
> B  B <xsl:template match="xsl:stylesheet"/>
> B </xsl:stylesheet>
> B <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">
> B <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

Current Thread