So here's a rundown of the "patterns" I use — yet there's still other ways to do it; usually depends on how much they differ, but here goes:
Doing the exact same in more than one template
Just join the element names with a pipe character in the match attribute:
<xsl:template match="Destination | TekstSide">
<!-- Do something -->
</xsl:template>
Extending the output of one template in another
Give the reusable template a name attribute, which enables it to be called from another template,
keeping its context (so when called from the Destination/TekstSide template, using @nodeName
will refer to @nodeName on the TekstSide document):
<xsl:template match="Destination" name="DestinationOutput">
...
</xsl:template>
<xsl:template match="Destination/TekstSide">
<!-- Render the output of the Destination template -->
<xsl:call-template name="DestinationOutput" />
<!-- Output specific to TekstSide -->
...
</xsl:template>
Using a common output template with a mode attribute
Works kind of the same as the above, but has the benefit of still using the matching rules,
so you can still create a specific template for one/some of them:
<xsl:template match="Destination | TekstSide">
<section>
<xsl:apply-templates select="." mode="output" />
</section>
</xsl:template>
<xsl:template match="Destination/TekstSide">
<div>
<xsl:apply-templates select="." mode="output" />
</div>
</xsl:template>
<xsl:template match="*" mode="output">
<!-- Common output for TekstSide and Destination -->
</xsl:template>
<xsl:template match="TekstSide/TekstSide" mode="output">
<!-- Specific output for TekstSide documents below another TekstSide (will still be wrapped in a <section>) -->
</xsl:template>
Enjoy!
(Remember it's still perfectly legal to have a single template with an <xsl:if> when the change is very simple :-)
The same html in 2 different template
Hi
it is possible to write the html in a variable and then insert it into the templates.
The point is to only write the Html once :-)
Hi Kate,
If you're doing exactly that, you can use a single template:
But somehow I get the idea that you want to do more in one of them? :)
/Chriztian
Nope, just for once Im making it simpel ;-) and it works perfectly. So Thanks for your help
But now I have become curious. What if I want to do more in one of the templates. Is there an easy way to do that?
Haha - you asked for it :-)
So here's a rundown of the "patterns" I use — yet there's still other ways to do it; usually depends on how much they differ, but here goes:
Doing the exact same in more than one template
Just join the element names with a pipe character in the match attribute:
Extending the output of one template in another
Give the reusable template a name attribute, which enables it to be called from another template, keeping its context (so when called from the Destination/TekstSide template, using
@nodeName
will refer to@nodeName
on the TekstSide document):Using a common output template with a mode attribute
Works kind of the same as the above, but has the benefit of still using the matching rules, so you can still create a specific template for one/some of them:
Enjoy!
(Remember it's still perfectly legal to have a single template with an
<xsl:if>
when the change is very simple :-)/Chriztian
Hi Chriztian
It seems interesting out, I will try it tomorrow
Thanks, for your help all day. It has been educational :-)
/Kate
Hi Chriztian
I'm sorry to bother you again, but you were right. It is not enough that I can insert the same html on two diffrent templat, I also want it to be recursiv :-)
The content I insert on the template "Destination" must also be shown on the Template TekstSide.
My xslt looks like this now:
I thought I could just write <xsl:value-of select="$Destination/headerProject" /> but that gives me an error.
Do you have the time to help me again :-)
/Kate
It works now.
is working on a reply...