XSL- Multiple Template Conflict?

2019-08-27 14:25发布

问题:

I'm currently working on an XSL stylesheet for some finding aids, but I believe I have a conflict between multiple templates in the stylesheet. Granted, I'm fairly new to XSL, so I'm probably missing something here. I hope I've included all the necessary details.

Here is the code I want the templates to act upon:

<c05 level="item"><did><unittitle><title render="italic">Souvenir</title>, undated</unittitle></did>
<scopecontent>
<p>With sketches of Confederate Generals and Confederate flags and a <emph render="doublequote">bird's eye view</emph> of Charleston.</p>
</scopecontent>
</c05>    

Now, the 2 templates in question format my container list layout and some text formatting respectively. The template for the layout is here:

<xsl:template name="item">

<xsl:variable name="title">

<xsl:if test="did/unitid">
<xsl:value-of select="did/unitid"/><xsl:text>.&#8201;</xsl:text>
</xsl:if>

<xsl:value-of select="did/unittitle"/>

<xsl:if test="did/unitdate">
<xsl:text>,&#8201;</xsl:text><xsl:value-of select="did/unitdate"/>
</xsl:if>

</xsl:variable>


<div style="margin-left:80px; padding-top:10px;"><xsl:value-of select="$title" /></div>


<div class="c01sc" style="margin-left:80px;"><xsl:value-of select="scopecontent" /></div>


<xsl:element name="a">
<xsl:call-template name="addidtoc"/>
</xsl:element>          

</xsl:template>

And here is the code for the text formatting. It calls another template that performs some formatting:

<xsl:template match='emph'>
    <xsl:call-template name='render'/>
</xsl:template>

<xsl:template name='render'>
    <xsl:choose>
    <xsl:when test="@render='italic'">
        <xsl:element name="i">
            <xsl:call-template name="addid"/>
            <xsl:apply-templates/>
        </xsl:element>
        </xsl:when>

etc.....

</xsl:template>

The problem is, only the actions of the first layout template are being performed. My layout styles are generated, but the area that should be in double quotes because of the emph tag are still plain. Is this an issue of template hierarchy, or have I done something completely wrong? Hopefully this makes some sense. I'd appreciate any help I can get!

回答1:

A named template is invoked only when you call it explicitly using xsl:call-template. A template rule (one with a match attribute) is invoked only when you select a node that it matches in an xsl:apply-templates instruction. This should explain why your templates are not executing.



标签: xml xslt