2013-02-09 132 views
0

我使用這些代碼隱藏我的方法,我的XML(WSDL)文件:多的<xsl:模板匹配的.xslt文件中的騾子

<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']" /> 

現在我想用短短條件隱藏所有的他們而不是多個如果。其實我用這個在我的.xslt文件中的一些行從一個特殊的IP地址隱藏我的方法:

<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地址,我不想寫所有我的方法這些代碼一個接一個。 我該如何做到這一點?

回答

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> 
+0

而且,我想隱藏這些:1.GetCityWeatherByZIPSoapIn 2.GetCityWeatherByZIPSoapOut 3.GetCityWeatherByZIPHttpGetIn 4.GetCityWeatherByZIPHttpGetOut 5. GetCityWeatherByZIP等等? – brelian 2013-02-09 06:12:52

+0

我有這個問題,我必須定義一個 brelian 2013-02-09 06:13:29

+0

@ user1976453我上面提供應隱藏_everything_其名稱的XSLT與 「GetCityWeatherByZIP」 開始,包括所有5你列出,只有這一個模板。你不需要製作它的多個副本。不,你只需要一次聲明變量。 – JLRishe 2013-02-09 06:35:55