XSLT:需要更换文件(“”)
我有以下XSLT文件:XSLT:需要更换文件(“”)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- USDomesticCountryList - USE UPPERCASE LETTERS ONLY -->
<xsl:variable name="USDomesticCountryList">
<entry name="US"/>
<entry name="UK"/>
<entry name="EG"/>
</xsl:variable>
<!--// USDomesticCountryList -->
<xsl:template name="IsUSDomesticCountry">
<xsl:param name="countryParam"/>
<xsl:variable name="country" select="normalize-space($countryParam)"/>
<xsl:value-of select="normalize-space(document('')//xsl:variable[@name='USDomesticCountryList']/entry[@name=$country]/@name)"/>
</xsl:template>
</xsl:stylesheet>
我需要更换“文件(‘’)” XPath函数,我应该怎么用呢? 我试图完全删除它,但xsl文件不适合我!
我需要如此,因为这个问题是:
我使用的是使用了上述文件中的一些XSLT文档,文件说一个。 所以我有文件a,其中包括上述文件(文件b)。
我使用DOC 一个从Java代码中,我为DOC 做高速缓存的作为javax.xml.transform.Templates对象,以防止多次读取到每个转换请求XSL文件。
我发现,文档b重新从硬盘调用自己,我相信这是因为上面的文档('')功能,所以我想要替换/删除它。
谢谢。
如果要访问变量内的节点,通常使用node-set()
扩展功能。可用性和语法取决于您使用的处理器。对于MSXML和Saxon,您可以使用exsl:node-set()。要使用扩展函数,您必须包含定义函数的名称空间。
E.g. (MSXML室内用测试,返回美国的国家名称= '美国'):
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl"
>
<xsl:output method="xml"/>
<!-- USDomesticCountryList - USE UPPERCASE LETTERS ONLY -->
<xsl:variable name="USDomesticCountryList">
<entry name="US"/>
<entry name="UK"/>
<entry name="EG"/>
</xsl:variable>
<!--// USDomesticCountryList -->
<xsl:template name="IsUSDomesticCountry">
<xsl:param name="countryParam"/>
<xsl:variable name="country" select="normalize-space($countryParam)"/>
<xsl:value-of select="exsl:node-set($USDomesticCountryList)/entry[@name=$country]/@name"/>
</xsl:template>
</xsl:stylesheet>
如果你想使IsUSDomesticCountry
模板的工作,而无需使用document('')
,你可以在模板改写为
<xsl:template name="IsUSDomesticCountry">
<xsl:param name="countryParam"/>
<xsl:variable name="country" select="normalize-space($countryParam)"/>
<xsl:choose>
<xsl:when test="$country='US'">true</xsl:when>
<xsl:when test="$country='UK'">true</xsl:when>
<xsl:when test="$country='EG'">true</xsl:when>
<xsl:otherwise>false</xsl:otherwise>
</xsl:choose>
</xsl:template>
或
<xsl:template name="IsUSDomesticCountry">
<xsl:param name="countryParam"/>
<xsl:variable name="country" select="normalize-space($countryParam)"/>
<xsl:value-of select="$country='US' or $country='UK' or $country='EG'"/>
</xsl:template>
甚至
<xsl:template name="IsUSDomesticCountry">
<xsl:param name="countryParam"/>
<xsl:variable name="country"
select="concat('-', normalize-space($countryParam),'-')"/>
<xsl:variable name="domesticCountries" select="'-US-UK-EG-'"/>
<xsl:value-of select="contains($domesticCountries, $country)"/>
</xsl:template>
个人,我发现使用document('')
的变体是更具可读性。
我需要从上面的代码做最小的更改,顺便说一句,谢谢:) – 2010-03-17 22:40:17
为什么你需要更换'文件( '')'?什么是实际问题? – markusk 2010-03-17 22:26:59