我有以下模板,它將顯示一個標籤,然後顯示它後面的值。告訴XSLT使用顯式模板而不是通配符
<xsl:template match="*" mode="row">
<xsl:param name="title"/>
<tr>
<td width="180">
<xsl:value-of select="$title"/>: </td>
<td>
<xsl:choose>
<xsl:when test="./*">
<xsl:for-each select="./*">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
在下列情況下調用:
<xsl:apply-templates select="Details/Detail/DateOfBirth" mode="row">
<xsl:with-param name="title">Date of birth</xsl:with-param>
</xsl:apply-templates>
<xsl:apply-templates select="Addresses" mode="row">
<xsl:with-param name="title">Address(s)</xsl:with-param>
</xsl:apply-templates>
現在 - 我不希望有我的每個應用模板時指定的標籤名,這應該是能夠由節點確定名稱。
所以我創建模板要應用的每個節點:
<xsl:template match="DateOfBirth">
<xsl:apply-templates select="." mode="row">
<xsl:with-param name="title">Date Of Birth</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Addresses">
<xsl:apply-templates select="." mode="row">
<xsl:with-param name="title">Address(s)</xsl:with-param>
</xsl:apply-templates>
</xsl:template>
並與調用這些:
<xsl:apply-templates select="Details/Detail/DateOfBirth" mode="row">
</xsl:apply-templates>
<xsl:apply-templates select="Addresses" mode="row">
</xsl:apply-templates>
但它應用通配符模板,使標籤空。有沒有辦法讓它更喜歡顯式模板?