Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dalton 14 posts 34 karma points
    Jun 17, 2011 @ 21:30
    dalton
    0

    xsl include feature

    I've been reading everything that comes up on google about this feature but still simply cannot get it to work correctly. So here is my xsl 

    <?xml version='1.0' encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "#x20;"> 
    ]>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:output method="html"/>
    
    <xsl:include href="header.xsl"/>
    
        <xsl:template match="/">
            stuff
        </xsl:template>
    </xsl:stylesheet>

    here is header.xsl

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
         version="1.0">
        <xsl:template name="page_header">
        <div style="background-color:#efefef;">Dalton was here</div>
        </xsl:template>
    
    </xsl:stylesheet>

    My thought is do I need to include the doctype in the one being included?or maybe not!

    please help me thanks to all!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jun 17, 2011 @ 23:13
    Tom Fulton
    1

    That looks correct, perhaps try moving the include to the bottom of the file though?

    Also, for more info on includes and examples check out Chriztian's blog post on them.

  • Lesley 284 posts 143 karma points
    Jun 18, 2011 @ 01:09
    Lesley
    2

    It looks to me like you're missing something to output your page_header template contents. So you could add

    <xsl:call-template name="page_header" />

    ...inside your main template.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 18, 2011 @ 21:56
    Chriztian Steinmeier
    1

    Hi Dalton,

    If your included stylesheet makes use of the &nbsp; entity, you'll need to have the DOCTYPE in that file as well, otherwise you don't.

    As Lesley points out, you just need to actually call the template you're including.

    The order of inclusion only matters if you're including templates that match the same elements as an already existing template in the master stylesheet - in this case, the template defined (or included) last in the stylesheet "wins".

    /Chriztian

  • dalton 14 posts 34 karma points
    Jun 20, 2011 @ 14:50
    dalton
    0

    thankyou all so much for your help. I just tried adding a doctype and call template and its still not doing anything here is what I have now look and see if there is anything else I'm doing wrong with this please.

    header.xsl

    <?xml version='1.0' encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "#x20;"> 
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
        <xsl:template name="custom_header">
            <div style="background-color:#efefef;">Dalton was here</div>
        </xsl:template>
    </xsl:stylesheet>
    Dalton was here
     

    main template.xsl

    <?xml version='1.0' encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "#x20;"> 
    ]>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    
    <xsl:include href="header.xsl"/>
    
    <xsl:template match="/">
      <html>
      <body>  
        <xsl:call-template name="custom_header" />
        <xsl:text>otherstuff</xsl:text>
      </body>
      </html>
    </xsl:template>
    </xsl:stylesheet>
  • dalton 14 posts 34 karma points
    Jun 20, 2011 @ 20:36
    dalton
    0

    Okay I got it working now thanks for the help. The major problem was the source code needed to transform the XML file to XHTML. The one I was using for some reason would not do includes but now im using a different one and it works perfectly.

Please Sign in or register to post replies

Write your reply to:

Draft