2011-11-01 52 views
0

這個問題與這個職位我的連接 - Will a Single XSLT file solve this issue..or...?單個XSLT文件能否解決此問題 - 延續..?

下面是我的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> 

下面是我的XSLT文件 - (以及Dimitre給了這個答案,但現在它);))

<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: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='*'"> 
    <xsl:call-template name="identity"/> 
    </xsl:if> 
</xsl:template> 

</xsl:stylesheet> 

上述XSLT將提取匹配從Java傳遞的。

現在我需要知道我可以修改這個XSLT,所以如果我通過甲骨文作爲參數,然後 那些誰在<CompSkills>有甲骨文將可以上市。將Oracle CompSkills之一..

預先感謝約翰 -

+0

除了'Name'或者'Name'之外,你還想獲得帶有「Oracle」的CV嗎? –

+0

@ DevNull- :)兩者的答案將是一個優勢。 :)非常感謝 - 約翰 – John

+0

我修改了我的答案,以便它匹配技能或名稱。希望這可以幫助。 –

回答

1

的XPath 1.0,簡單的方法:contains功能,例如:

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

@John,不客氣! –

1

您可以通過使用做到這一點。

樣式表將拉動CV如果Name匹配pName PARAM或者CompSkills包含pSkill PARAM的這個修改後的版本。

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

@ DevNull-非常感謝親愛的...... :) - 約翰 – John