开发者

Determining which disjunct in an xsl:template match matched

开发者 https://www.devze.com 2023-01-04 10:31 出处:网络
Suppose I have XML like this: <xsl:template match=\"assessment | section \"> . . . </xsl:template>

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"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消