Possible to have imported root template run first?

Say you have these two xsl files:

cow-wrapper.xsl

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:element name="cow">
            <next-match />
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

test.xsl

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:import href="cow-wrapper.xsl" />

    <xsl:template match="/">
        <!-- regular stuff to do -->
    </xsl:template>

</xsl:stylesheet>

In this case the root match in cow-wrapper.xsl is not called at all. Is there a way to make the root template match in cow-wrapper.xsl have presedence over the one in test.xsl?

What I'm after is a way to simply import a file and have it wrap the regular output. For example in a soap envelope.

Answers


From the XSLT spec, it looks like imported templates always have lower precedence than conflicting templates with higher import precedence (where the main XSLT would have the highest import precedence), but perhaps this is a suitable workaround?:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:element name="cow">
            <apply-templates select="." mode="regular">
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:import href="cow-wrapper.xsl" />

    <xsl:template match="/" mode="regular">
        <!-- regular stuff to do -->
    </xsl:template>

</xsl:stylesheet>

If I want the template in the imported template to be "executed" first, I would either not have a template in the importing stylesheet with the same match pattern, or I would write it this way:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:import href="cow-wrapper.xsl" />

    <xsl:template match="/">
        <xsl:next-match/>
        <!-- regular stuff to do -->
    </xsl:template>
</xsl:stylesheet>

Need Your Help

Deploying webapp on Tomcat7

java spring maven tomcat jetty

My problem is that I'm trying to deploy my spring-based webapp on Tomcat. Out of being used to that I embedded jetty for tests, and it worked fine. Whole app is responding correctly when I stop to...

How to extract column names from SQL Query as String SQL query is passed as a String

java api java-ee

An SQL Query will be passed to my Method as a String, How can i retrieve the Column names in the query, if the query is e.g.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.