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 08, 2011 @ 22:34
    dalton
    0

    Is it possible to create a 'Master' xsl which pulls in other xsl stylesheets?

    Im working on a big project for the NCAA and need help. Part of my task is to design reports using xsl to show all the game stats within every college sport for each game, season , career and confrence.

    My question is what is the syntax to make a seperate xsl stylesheet that I could use to merge multiple xsl stylesheets?

    Say I had 3 game reports with 3 seperate xsl sheets and i want to make a 4 sheet that draws them all in to display all of them together thats what I am wondering.

    Help will be greatly appreciated please and thankyou!

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jun 08, 2011 @ 22:47
    Chriztian Steinmeier
    0

    Hi dalton,

    You can use <xsl:include> and <xsl:import> to do such smartness - look here for an article about those: http://pimpmyxslt.com/articles/include-or-import/

    /Chriztian

  • dalton 14 posts 34 karma points
    Jun 08, 2011 @ 22:56
    dalton
    0

    Thankyou i've been googling for the past 30 mins trying to figure this out. I guess I just wasn't using the correct key words.

    Does this also use whatever xml the original imported xsl used or do you have to make a xml that has all the xml's in it from each of the imports?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jun 08, 2011 @ 23:14
    Chriztian Steinmeier
    0

    Think of it this way:

    When the XSLT processor is ready to work its magic, the "Master.xslt" file is seen as a single stylesheet.

    The XML your stylesheet is processing doesn't in any way "belong" to the XSLT file - it can really only come from a couple of different sources:

    • The main document that's the "real" (and only) input document - in Umbraco macros this will be a simple <macro /> element (maybe with a couple of parameters as childnodes)
    • Umbraco nodes from the tree, supplied in the $currentPage parameter
    • External XML, fetched via the document() function or some extension function 

    So your imported/included templates will not carry any data over - they're simply templates that define output for various elements that may or may not be present in the XML you're processing...

    Hope I didn't go too far into la-la land :-)  - keep asking if you need more help.

    /Chriztian

  • dalton 14 posts 34 karma points
    Jun 10, 2011 @ 14:52
    dalton
    0

    Okay so im still a little confused so for example so this is what I have

    I have one of these xml files for each xsl that kinda of look like this 
    
    <report>
        <stats>
            <blah>something</blah>
        </stats>
    </report>

    so your saying I neeed to put all of these xml files into a bigger xml file

    It would be something like this and then it would be used for the new combined xsl
    
    <reports>
        <report>
            <stats>
                <blah>something</blah>
            <stats>
        </report>
        <report>
            <stats>
                <player>something diferent</player>
            <stats>
        </report>
    </reports>

    Is this how it needs to be?

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jun 10, 2011 @ 20:31
    Chriztian Steinmeier
    0

    Hi dalton,

    Yes - but you don't have to manually assemble them - you can do something like this:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <!-- Collect data -->
            <xsl:variable name="report1" select="document('http://domain.com/report1.xml')/report" />
            <xsl:variable name="report2" select="document('http://domain.com/report2.xml')/report" />
    
            <!-- Join the reports and start processing -->
            <xsl:apply-templates select="$report1 | $report2" />
    
        </xsl:template>
    
    
        <!-- Include templates for formatting -->
        <xsl:include href="ReportFormatter-1.xslt" />
        <xsl:include href="ReportFormatter-2.xslt" />
    
    </xsl:stylesheet>
    
    <!-- In "ReportFormatter-1.xslt": -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="report">
            <p>
                <!-- do stuff -->
            </p>
        </xsl:template>
    
        <!-- etc. -->
    
    </xsl:stylesheet>
    
    <!-- In "ReportFormatter-2.xslt" -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="report[@data = 'important']">
            <p>
                <!-- do some more -->
            </p>
        </xsl:template>
    
        <!-- etc. -->
    
    </xsl:stylesheet>

    /Chriztian 

  • dalton 14 posts 34 karma points
    Jun 10, 2011 @ 21:46
    dalton
    0

    Wow your really good at this stuff. Haha I just started but I understand it more and more everyday Thankyou so much for all the help I do have one last question though if you care to give me your thought.

    So I got my xml report that looks like I showed you in the reply above so ...

    <reports>
        <report>
            <report_type>box_score</report_type>
        </report>
        <report>
            <report_type>play-by-play</report_type>
        </report>
        <report>
            <report_type>shot-chart</report_type>
        </report>
    </reports>

    I have been reading a lot about the include import functions and this is what ive been trying but it doesnt seem to work

    <xsl:template match="/">
      <html>
        <head>
            <link rel="stylesheet" href="reports.css"/>   
        </head>
      <body>  
        <!--Insert custom header here --> 
        <xsl:apply-templates select="reports"/>
        <!--Insert custom footer here -->
      </body>
      </html>
    </xsl:template>
    
    <xsl:template match="reports">
        <table width="100%" cellpadding="0" cellspacing="0">
            <tr class="title2">
                <td><h3>Soccer Box Score</h3></td>
            </tr>
        </table>
        <xsl:for-each select="report">
                <xsl:if test="report_type='box_score'">
            <xsl:include href="box_score_report.xsl" />
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

    Thanks, Dalton

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Jun 11, 2011 @ 00:20
    Chriztian Steinmeier
    0

    Hi Dalton,

    You can't do that I'm afraid, but it's just a matter of thinking a little different.

    First of all, the include/import step happens *before* the transformation is started (kind of analogous to a C# using statement - you can't do that conditionally either) and they have to be placed at top-level (meaning as child nodes of the xsl:stylesheet element, though not necessarily at the top of the file).

    Here's a rewritten version of how I'd structure what you're showing us:

    <?xml version="1.0" encoding="utf-8" ?>
    <xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:umb="urn:umbraco.library"
        exclude-result-prefixes="umb"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
    
        <xsl:template match="/">
            <!-- Collect data -->
            <xsl:variable name="boxScore" select="document('http://domain.com/report-box-score.xml')/report" />
            <xsl:variable name="playByPlay" select="document('http://domain.com/play-by-play.xml')/report" />
    
            <!-- Join the reports and start processing -->
            <xsl:apply-templates select="$boxScore | $playByPlay" />
    
        </xsl:template>
    
    
        <!-- Include templates for formatting -->
        <xsl:include href="BoxScoreReport.xslt" />
        <xsl:include href="PlayByPlayReport.xslt" />
    
    </xsl:stylesheet>
    
    <!-- In "BoxScoreReport.xslt": -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="report[report_type = 'box_score']">
            <p>
                <!-- do stuff -->
            </p>
        </xsl:template>
    
        <!-- etc. -->
    
    </xsl:stylesheet>
    
    <!-- In "PlayByPlayReport.xslt" -->
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:template match="report[report_type = 'play-by-play']">
            <p>
                <!-- do some other stuff -->
            </p>
        </xsl:template>
    
        <!-- etc. -->
    
    </xsl:stylesheet>

    The included templates will be automatically applied to their mathing report elements based on the match attributes.

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft