This question is connected with this post of mine – Will a Single XSLT file solve this issue..or…?
Below is my XML file –
<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>
Below is my XSLT file – (well Dimitre gave this answer, but now its mine 😉 )
<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>
The above XSLT will extract matching <Name> which is passed from Java.
Now I need to know how can i modify this XSLT, so that if I pass Oracle as a parameter, then
those who have Oracle in <CompSkills> would get listed. Oracle will be one of the CompSkills..
Thanks in advance – John
XPath 1.0, easy way:
containsfunction, e.g.: