Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 一个XSLT文件能否解决这个问题-continuation。。?_Java_Xml_Xslt_Xpath - Fatal编程技术网

Java 一个XSLT文件能否解决这个问题-continuation。。?

Java 一个XSLT文件能否解决这个问题-continuation。。?,java,xml,xslt,xpath,Java,Xml,Xslt,Xpath,这个问题与我的这个职位有关- 下面是我的XML文件- <CVs> <CV> <Name>ABC</Name> <Address></Address> <Introduction></Introduction> <CompSkills>Java, XSLT, XPATH, XML, Oracle, VB.NET</CompSkills> <Experi

这个问题与我的这个职位有关-

下面是我的XML文件-

<CVs>
 <CV>
  <Name>ABC</Name>
  <Address></Address>
  <Introduction></Introduction>
  <CompSkills>Java, XSLT, XPATH, XML, Oracle, VB.NET</CompSkills>
  <Experience>
    <Profile></Profile>
    <Duration></Duration>
    <Info></Info>
  </Experience>
  <Experience>
    <Profile></Profile>
    <Duration></Duration>
    <Info></Info>
  </Experience>
  <Experience>
    <Profile></Profile>
    <Duration></Duration>
    <Info></Info>
  </Experience>
<CV>
<CV>
 <Name>XYZ</Name>
 <Address></Address>
 <Introduction></Introduction>
 <CompSkills>Java, XSLT, XPATH, XML, JSP, HTML</CompSkills>
 <Experience>
   <Profile></Profile>
   <Duration></Duration>
   <Info></Info>
 </Experience>
 <Experience>
   <Profile></Profile>
   <Duration></Duration>
   <Info></Info>
 </Experience>
 <Experience>
   <Profile></Profile>
   <Duration></Duration>
   <Info></Info>
 </Experience>

基础知识
Java、XSLT、XPATH、XML、Oracle、VB.NET
XYZ
Java、XSLT、XPATH、XML、JSP、HTML

下面是我的XSLT文件-(Dimitre给出了这个答案,但现在是我的;)


上面的XSLT将提取从Java传递的匹配的

现在我需要知道如何修改这个XSLT,如果我将Oracle作为参数传递,那么 那些在
中拥有Oracle的人将被列入名单。Oracle将是CompSkills之一

提前感谢-John

XPath 1.0,简易方法:函数,例如:

<xsl:if test="contains(CompSkills, $pSkill)">

您可以使用
contains()
完成此操作

如果
名称
pName
参数匹配,或者
CompSkills
包含
pSkill
参数,则样式表的此修改版本将拉取
CV

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="pName" select="'XYZ'"/>
  <xsl:param name="pSkill" select="'Oracle'"/>

  <xsl:template match="node()|@*" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="CV">
    <xsl:if test="$pName = Name or $pName='*' or
                  contains(CompSkills,$pSkill)">
      <xsl:call-template name="identity"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>


除了
名称
之外,您是否希望获得带有“Oracle”的
简历
,或者不想要
名称
?@DevNull-:)这两种答案都是一种优势。:)非常感谢-JohnI修改了我的答案,使之与技能或名称匹配。希望这有帮助。@DevNull-非常感谢亲爱的…:)-约翰
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes" indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:param name="pName" select="'XYZ'"/>
  <xsl:param name="pSkill" select="'Oracle'"/>

  <xsl:template match="node()|@*" name="identity">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="CV">
    <xsl:if test="$pName = Name or $pName='*' or
                  contains(CompSkills,$pSkill)">
      <xsl:call-template name="identity"/>
    </xsl:if>
  </xsl:template>

</xsl:stylesheet>