2011-04-01 184 views
0

Helo,我正在尋找在xsl中執行搜索功能以在xml文件中查找關鍵字。我使用了關鍵功能,但它只能完全找到指定的單詞。例如,我想要輸入單詞「com」,我希望它找到包含「com.infopro」或任何包含此字符串的單詞。使用xsl進行搜索


XML

<?xml version="1.0" encoding="utf-8" ?> 

<!DOCTYPE dependencies SYSTEM "http://depfind.sourceforge.net/dtd/dependencies.dtd"> 

<dependencies> 
    <package confirmed="yes"> 
     <name>com.infopro.Dependency</name> 
     <class confirmed="yes"> 
      <name>com.infopro.Dependency.A</name> 
      <outbound type="class" confirmed="no">java.lang.Object</outbound> 
      <outbound type="class" confirmed="no">javax.ejb.Stateless</outbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.B()</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.a</inbound> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.A()</name> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.b</outbound> 
       <outbound type="class" confirmed="yes">com.infopro.Dependency.B</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.B()</outbound> 
       <outbound type="feature" confirmed="no">java.lang.Object.Object()</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.B()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.b</name> 
       <outbound type="class" confirmed="yes">com.infopro.Dependency.B</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.A()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.check(java.lang.String, java.lang.String)</name> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.stat</outbound> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.doStatus()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.doStatus()</name> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.check(java.lang.String, java.lang.String)</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.name</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.user_id</outbound> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.name</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.doStatus()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.stat</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.check(java.lang.String, java.lang.String)</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.A.user_id</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.doStatus()</inbound> 
      </feature> 
     </class> 
     <class confirmed="yes"> 
      <name>com.infopro.Dependency.B</name> 
      <outbound type="class" confirmed="yes">com.infopro.Dependency.C</outbound> 
      <outbound type="class" confirmed="no">java.lang.Object</outbound> 
      <outbound type="class" confirmed="no">javax.ejb.Stateless</outbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.A()</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.b</inbound> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.B()</name> 
       <outbound type="class" confirmed="yes">com.infopro.Dependency.A</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.A.A()</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.a</outbound> 
       <outbound type="feature" confirmed="no">java.lang.Object.Object()</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.A()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.a</name> 
       <outbound type="class" confirmed="yes">com.infopro.Dependency.A</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.B()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.check(java.lang.String, java.lang.String)</name> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.stat</outbound> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.doStatus()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.doStatus()</name> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.check(java.lang.String, java.lang.String)</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.name</outbound> 
       <outbound type="feature" confirmed="yes">com.infopro.Dependency.B.user_id</outbound> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.name</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.doStatus()</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.stat</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.check(java.lang.String, java.lang.String)</inbound> 
      </feature> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.B.user_id</name> 
       <outbound type="class" confirmed="no">java.lang.String</outbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.doStatus()</inbound> 
      </feature> 
     </class> 
     <class confirmed="yes"> 
      <name>com.infopro.Dependency.C</name> 
      <outbound type="class" confirmed="no">java.lang.Object</outbound> 
      <outbound type="class" confirmed="no">javax.ejb.Remote</outbound> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.B</inbound> 
      <feature confirmed="yes"> 
       <name>com.infopro.Dependency.C.doStatus()</name> 
      </feature> 
     </class> 
    </package> 
    <package confirmed="no"> 
     <name>java.lang</name> 
     <class confirmed="no"> 
      <name>java.lang.Object</name> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.A</inbound> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.B</inbound> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.C</inbound> 
      <feature confirmed="no"> 
       <name>java.lang.Object.Object()</name> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.A()</inbound> 
       <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.B()</inbound> 
      </feature> 
     </class> 
     <class confirmed="no"> 
      <name>java.lang.String</name> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.check(java.lang.String, java.lang.String)</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.doStatus()</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.name</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.stat</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.A.user_id</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.check(java.lang.String, java.lang.String)</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.doStatus()</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.name</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.stat</inbound> 
      <inbound type="feature" confirmed="yes">com.infopro.Dependency.B.user_id</inbound> 
     </class> 
    </package> 
    <package confirmed="no"> 
     <name>javax.ejb</name> 
     <class confirmed="no"> 
      <name>javax.ejb.Remote</name> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.C</inbound> 
     </class> 
     <class confirmed="no"> 
      <name>javax.ejb.Stateless</name> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.A</inbound> 
      <inbound type="class" confirmed="yes">com.infopro.Dependency.B</inbound> 
     </class> 
    </package> 
</dependencies> 

XSL

<xsl:output method="text"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="class"> 
    <xsl:text></xsl:text><xsl:value-of select="name"/><xsl:if test="@confirmed='no'"> *</xsl:if><xsl:text> </xsl:text> 
    <xsl:for-each select="key('cdlist','com')"> 
     <xsl:text disable-output-escaping="yes">                    , </xsl:text><xsl:value-of select="."/><xsl:if test="@confirmed='no'"> *</xsl:if><xsl:text> 

,*

回答

0

總是有XPath的包含您可以使用()函數。

<xsl:apply-templates select="class[contains(.//text(), 'com')]">