#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0

    embed xsl


    split from http://forums.devshed.com/showthread.php?t=77694 --requinix

    Hello I'm new to this Forum!

    I'm currently also trying to embed XSL directly into an XML file - so far so good. I also tried the examples mentioned above. My problem is the following. But first the sample code here:

    Code:
    <?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="W3 XSL Transformation">     
      <xsl:output method="html"/>
      <xsl:template match="/">
        <html>
          <head>
            <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>
    The example works fine in Safari 5 but not in Firefox 4. Well in Firefox it shows "This is the title" twice, but without formatation. Interestingly, if I remove the xmlns="urn:asdf" and xmlns:n1="urn:asdf" everthing works quite fine - in Safari and Firefox. However nothing is presented if I write xmlns="urn:asdf" in the target-Tag and the xsl:stylesheet-Tag.

    Anyway why is it necessary to define xmlns for the XML and the XSL even if it's the same? Why do I have to add ":n1" for the xmlns in the stylesheet? And why is there no problem at all, when I remove both xmlns instructions?

    I would be grateful for any help. Thank you.

    _gabe_
    Last edited by requinix; April 11th, 2011 at 03:52 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2009
    Posts
    191
    Rep Power
    49
    Problem is namespace

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type='text/xsl' href='#test'?>
    <!DOCTYPE n1:target [
    	<!ELEMENT xsl:value-of EMPTY>
    <!ATTLIST xsl:value-of
    	select CDATA #FIXED "n1:target/n1:title"
    >
    <!ELEMENT xsl:template ((html))>
    <!ATTLIST xsl:template
    	match CDATA #FIXED "/"
    >
    <!ELEMENT xsl:stylesheet ((xsl:output, xsl:template))>
    <!ATTLIST xsl:stylesheet
    	id CDATA #FIXED "test"
    	version CDATA #FIXED "1.0"
    	xmlns:n1 CDATA #FIXED "urn:asdf"
    	xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
    >
    <!ELEMENT xsl:output EMPTY>
    <!ATTLIST xsl:output
    	method CDATA #FIXED "html"
    >
    <!ELEMENT title ((xsl:value-of))>
    <!ELEMENT n1:title (#PCDATA)>
    <!ELEMENT n1:target ((xsl:stylesheet, n1:title))>
    <!ATTLIST n1:target
    	xmlns:n1 CDATA #FIXED "urn:asdf"
    >
    <!ELEMENT html ((head, body))>
    <!ELEMENT head ((title))>
    <!ELEMENT h1 ((center))>
    <!ELEMENT center ((xsl:value-of))>
    <!ELEMENT body ((h1))>
    ]>
    <n1:target xmlns:n1="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"/>
    		<xsl:template match="/">
    			<html>
    				<head>
    					<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:stylesheet>
    	<n1:title>This is the title</n1:title>
    </n1:target>
    tested opera9 firefox4 ie8

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>This is the title</title>
    </head>
    <body>
    <h1>
    <center>This is the title</center>
    </h1>
    </body>
    </html>
    Helmut Hagemann Germany

    fallen to the bottom of the facts?
    I reach my hand and we go together


    wer lesen und google kann ist klar im Vorteil
    who read and google is able is clear in the advantage
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    5
    Rep Power
    0
    Thx Helmut for your reply.

    I see the point. But why does everything work quite smoothly if i put the stylesheet in a separate file? So we have the XML and the XSL:

    Code:
    <?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>
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:n1="urn:asdf" version="1.0" xmlns:xsl=""> 
      <xsl:output method="html"/>
      <xsl:template match="/">
        <html>
          <head>
            <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>
    Why is Firefox not able to interpret the style correctly, if its embedded in the XML as shown in my first post? Whereas - if I analyse the generated Code with WebDeveloper it seems to be transformed correctly - only presentation fails.

    Thx in advance, _gabe_

IMN logo majestic logo threadwatch logo seochat tools logo