views:

163

answers:

2

Hello guys,

I've got an interesting question on XSLT import/include.

I have 2 XSLT files with the same rule.

Receipt XSLT: (is run by itself)

<xsl:template match="Booking" mode="extraStyle">
 <link rel="stylesheet" href="../css/receipt.css" type="text/css" media="screen"/>
</xsl:template>

EmailCommon XSLT: (serves as template library for Email docs, isn't run by itself)

 <xsl:template match="Booking" mode="extraStyle">
    <link rel="stylesheet" href="../css/email.css" type="text/css" media="screen"/>
 </xsl:template>

So that depending on the document type I insert correct CSS files.

What I'm trying to do is to include these two documents into yet another XSLT:

<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
exclude-result-prefixes="msxsl" 
version="1.0">

<xsl:include href="receipt.xsl"/>
<xsl:include href="email.xsl"/>

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

Nevertheless, because the rules are the same in both included stylesheets it boils down to the Last-in-first rule and I end up only including email.css.

I was wondering if something smart could be done in this case?

The only thing I was thinking is to using different mode, but then it wouldn't be as intuitive, rather then accumalate the code of all identical rules. Don't know how and whether at all it could be done in XSLT.

Thanks for help!

P.S. Sorry, I'm really trying to understand the formating rules on this site, but I simply can't :( gggrrr

A: 

I am trying to understand what you mean when you say "depending on the document type".

Could you post an example of two different documents that you want to activate the two different templates?

martin jakubik
+1  A: 

I think making the template modes different is your best option.

<xsl:stylesheet 
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
  exclude-result-prefixes="msxsl" 
>

  <xsl:include href="receipt.xsl"/>
  <xsl:include href="email.xsl"/>

  <xsl:template match="Booking">
    <xsl:apply-templates select="." mode="extraStyleReceipt" />
    <xsl:apply-templates select="." mode="extraStyleEmail" />
  </xsl:template>

</xsl:stylesheet>
Tomalak