是否可以将模板应用于属性? 我写了一个XSL,它以正确的顺序打印出地址所在国家的地址。例如:
澳大利亚:
Honorific FirstName LastName
CompanyName
.
.
巴西:
CompanyName
Honorific FirstName LastName
我的XML看起来像:
<Addresses locale="AUS">
<Address>
<Honorific/>
<FirstName/>
<LastName/>
<CompanyName>Name of the Company</CompanyName>
<CompanyName2/>
<Address1>Mainstreet 17</Address1>
<Address2/>
<PostalCode>59943</PostalCode>
<City>Somewhere</City>
<City2/>
<District/>
<State/>
</Address>
我的XML是由数据库生成的,所以根据我选择的国家/地区,我会得到0到X的地址。因为有大约30种不同的方式来写一个地址(在不同的国家),我必须将模板应用于每个可能的语言环境。像:
<xsl:template match="/Addresses">
<xsl:choose>
<xsl:when test=" @locale='PH' ">
<xsl:apply-templates mode="PH" />
</xsl:when>
<xsl:when test=" @locale='AUS' ">
<xsl:apply-templates mode="AUS" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="#default" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
我现在的问题是,有办法说:
<xsl:apply-templates mode="@locale">
或将语言环境存储在变量中并将其置于我的模式中..
谢谢!
答案 0 :(得分:2)
个别模板怎么样?
<xsl:template match="/Addresses[@locale='PH']">
...
</xsl:template>
<xsl:template match="/Addresses[@locale='AUS']">
...
</xsl:template>
<xsl:template match="/Addresses">
... the default one ...
</xsl:template>