xsl-list
[Top] [All Lists]

[xsl] XSL embedded in XML

2011-04-18 07:16:36
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>
--~--

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