tags:

views:

136

answers:

3

I need to create XSL that checks a "does not contain" condition. For example, my XML is like this:

<Categories>
  <category>
    <blog>ABC</blog>
    <link>http://www.msdn.com&lt;/link&gt;
  </category>
</Categories>

I want to show every <blog> where <link> does not contain "msdn". I don't want to use equals because I just want to check part of the link.

+1  A: 

Use the not function with the contains function.

Example: not(contains('XML','XM'))

Result: false

http://www.w3schools.com/Xpath/xpath_functions.asp

Sam T.
Thanks for the reply it solved my prblem but can you tell me I want to display msg like record not found when the count is 0 for not(contains(link,msdn)) ....how to achieve this
TSSS22
seeing as this is really an independent question, you should create a new post for it.
Sam T.
check this out: http://www.stylusstudio.com/w3c/xslt/message.htm
Sam T.
+4  A: 

I'm not sure exactly what HTML output you want, but hopefully this can get you started.

<xsl:template match="category">
    <xsl:if test="not(contains(link, 'msdn'))">
        <a href="{link}">
            <xsl:value-of select="blog" />
        </a>
    </xsl:if>
</xsl:template>

You could also include the test in the template match (or the apply-templates select) predicate like this:

<xsl:template match="category[not(contains(link, 'msdn'))]">
Peter Jacoby
I would probably check for `not(starts-with(substring-after(link, '://'), 'www.msdn.com'))`, to make the match unambiguous.
Tomalak
yup its working fine thanks ...
TSSS22
Do you have any idea how to check that not(contains()) count is zero
TSSS22
You could do add something like count(blog[not(contains(following-sibling::link, 'msdn'))]) to get the number of matching blog nodes and use an xsl:choose for the different sections.
Peter Jacoby
A: 

Xpath for xsl:apply-templates or xsl:value-of should contain following

/Categories/category/blog[not( contains(following-sibling::link/text(), 'msdn'))]
Dewfy