我使用这些代码将我的方法隐藏在我的XML(WSDL)文件中:
<xsl:template match="wsdl:operation[@name = 'GetCityWeatherByZIP']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPSoapIn']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPSoapOut']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPHttpGetIn']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPHttpGetOut']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPHttpPostIn']" />
<xsl:template match="wsdl:message[@name = 'GetCityWeatherByZIPHttpPostOut']" />
<xsl:template match="s:element[@name = 'GetCityWeatherByZIP']" />
<xsl:template match="s:element[@name = 'GetCityWeatherByZIPResponse']" />
现在我想只使用一个条件隐藏所有这些而不是多个if。实际上我在.xslt文件中使用了一些行来隐藏我的方法来处理特殊的ip-address:
<xsl:template match="wsdl:operation[@name = 'GetCityWeatherByZIP']">
<xsl:variable name="rcaTrimmed"
select="substring-before(substring-after($remoteClientAddress, '/'), ':')" />
<xsl:if test="not($rcaTrimmed = '192.168.3.74')">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:if>
</xsl:template>
我想在一行中添加我的所有**<xsl:template match**
,然后从特殊的ip地址中隐藏所有这些,我不想为我的所有方法编写这些代码一个接一个。
我怎样才能达到这个目的?
答案 0 :(得分:1)
您是否只想隐藏以“GetCityWeatherByZIP”开头的@name
的所有内容?如果是这样,您可以使用此单一模板:
<xsl:template match="*[starts-with(@name, 'GetCityWeatherByZIP')]">
<xsl:variable name="rcaTrimmed"
select="substring-before(substring-after($remoteClientAddress, '/'), ':')" />
<xsl:if test="not($rcaTrimmed = '192.168.3.74')">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:if>
</xsl:template>
我还建议将rcaTrimmed
变量的定义移到模板之外,这样只需要计算一次:
<xsl:variable name="rcaTrimmed"
select="substring-before(substring-after($remoteClientAddress, '/'), ':')" />
<xsl:template match="*[starts-with(@name, 'GetCityWeatherByZIP')]">
<xsl:if test="not($rcaTrimmed = '192.168.3.74')">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:if>
</xsl:template>