Suppose I have XML like this:
<xsl:template match="assessment | section ">
.
.
.
</xsl:template>
I do this because I mostly want to treat assessment
and section
nodes the same. However, I do want to treat th开发者_如何学Pythonem a little differently. How can I tell whether a match was for assessment
or for section
?
Do something like this:
<xsl:if test="name()='section'">
</xsl:if>
You may test for:
self::assessment
which is slightly more efficient than using the name()
function.
However in cases like this I will put the common code in another template (either named or in a named mode) and will instantiate the common processing like this:
<xsl:apply-templates select="." mode="common"/>
精彩评论